Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    simple rating script errors Warning: mysql_num_rows(): supplied argument is not a val

    Hi have am new to php this is one of my first hand writen script its just a basic rating script, im getting some errors i cant work out, any help would be great. google says it may be because the script cant find the database but it is because it told me it couldnt find some colums, but when i got rid of the spelling mistakes im still getting errors.

    below is my code and erors

    PHP Code:
    <?php
    $id 
    $_POST['id'];

    //Grabing the details from the name table

    $connection=mysql_connect("localhost","username""password") or die("Unable to connect!"); /* change this! */ 

    mysql_select_db("database") or die("Unable to select database!"); /* change this! */ 

    $result "SELECT * FROM name WHERE id='$id'";
    $numrow mysql_num_rows ($result);

    // converting thenm into objects
    $row mysql_fetch_array($result);

    $domain GetHostByName($REMOTE_ADDR);
    $submit_rating $_POST['rate'];
    $num_votes $row["num_votes"];
    $votes_total $row["votes_total"];
    $new_num_votes =  ($num_votes 1);
    $new_votes_total = ($votes_total $submit_rating);
    $rating = (new_votes_total $new_num_votes);


     
    $query2 "UPDATE name SET `num_votes` = '$new_num_votes',
    `votes_total` = '$new_votes_total',
    `rating` = '$rating'" 
    ;


    $result2=mysql_query($query2) or die("Error in query:".mysql_error()); 
    //if ($result) 
        //echo mysql_affected_rows()." row inserted into the database effectively."; 

    //  CLOSE CONNECTION ---> 

    header ("Location:".$_SERVER['HTTP_REFERER']." ");



    mysql_close($connection); 
    ?>

    errors:
    Code:
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/tyspicsc/public_html/posthate/rating_action.php on line 11
    
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/tyspicsc/public_html/posthate/rating_action.php on line 14
    
    Warning: Cannot modify header information - headers already sent by (output started at /home/tyspicsc/public_html/posthate/rating_action.php:11) in /home/tyspicsc/public_html/posthate/rating_action.php on line 36

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,107
    Thanks
    2
    Thanked 326 Times in 318 Posts
    Somewhere prior to the mysql_num_rows(...) statement, there needs to be a mysql_query(...) statement -
    PHP Code:
    $result "SELECT * FROM name WHERE id='$id'"
    $numrow mysql_num_rows ($result); 
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Location
    N. Ireland
    Posts
    351
    Thanks
    16
    Thanked 4 Times in 4 Posts
    yeah do:
    Code:
    $sql = "SELECT * FROM name WHERE id='$id'";
    $result = mysql_query($result)
    $numrow = mysql_num_rows ($result);
    Hope this helps.

    D.

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Be sure to check the query to make sure it succeeded too.
    PHP Code:
    $sql "SELECT * FROM name WHERE id='$id'";
    $result mysql_query($sql);
    if (!
    $result) {
        die(
    "SQL Error! $sql<br />".mysql_error());
    }
    $numrow mysql_num_rows ($result); 
    Last edited by Fumigator; 06-07-2007 at 10:48 PM. Reason: to fix the code

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,107
    Thanks
    2
    Thanked 326 Times in 318 Posts
    It would also help if the $sql variable was used instead of $result in the mysql_query(...) function call in the above two posts.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #6
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you so much everyone it is working perfect now


  •  

    Posting Permissions

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