Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    7,554
    Tokens
    0

    Latest Awards:

    Default mysql_num_rows is empty?? +rep

    G'day everyone.

    I have a quick question. This is starting to piss me off to the max :eusa_wall!!

    Why doesn't this code work?
    PHP Code:
    <?php
    include("includes/connect.php");

            
    $sender $_SESSION['username'];
            
    $reciever "lol";
            
    $message $_POST['message'];
            
    $date date("d/m/Y");
            
    $status "unread";
            
            
    $sql "SELECT * FROM `members` WHERE `username`='{$reciever}'";
            
    $query mysql_query($sql) or die(mysql_error());
            
    $num_rows mysql_num_rows($query) or die(mysql_error());
            echo(
    "$num_rows");
    ?>
    The reciever is a made up name, but that should return "0" yeah?? Well, it kinda just ends the script.

    The following script works:
    PHP Code:
    <?php
    include("includes/connect.php");

            
    $sender $_SESSION['username'];
            
    $reciever "shane";
            
    $message $_POST['message'];
            
    $date date("d/m/Y");
            
    $status "unread";
            
            
    $sql "SELECT * FROM `members` WHERE `username`='{$reciever}'";
            
    $query mysql_query($sql) or die(mysql_error());
            
    $num_rows mysql_num_rows($query) or die(mysql_error());
            echo(
    "$num_rows");
    ?>


    okay, i figured it is this part (the bold one) because if i remove that part, it runs fine..:
    $num_rows = mysql_num_rows($query) or die(mysql_error());

    Moved by ReviewDude (Forum Moderator) from "Web Design", this is a coding-related issue.
    Last edited by ReviewDude; 25-03-2009 at 07:54 AM.

  2. #2
    Join Date
    Feb 2009
    Location
    Suffolk
    Posts
    327
    Tokens
    0

    Default

    why dot you remove the mysql error then?

  3. #3
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    7,554
    Tokens
    0

    Latest Awards:

    Default

    Because wouldn't it be safer to have that :S? And to practice 'good coding'

  4. #4
    Join Date
    Feb 2009
    Location
    Suffolk
    Posts
    327
    Tokens
    0

    Default

    its a tiny bit safer, but if you come across these errrors and need them fixed, you have to do what it takes.
    it doesnt really matter if its there or not.

    sure it would practise 'good' coding, but then again, its not exactly 'bad' coding, and you could always code some different stuff

  5. #5
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    Its annoying when people ask for help and don't post the error in question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •