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 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with mysql error

    here is my code:
    PHP Code:
    <?php

    $desire_schedule 
    '0';

    if(isset(
    $_POST['update_users'])){

        echo 
    '<br /><div align="center">';

            if(isset(
    $_POST['schedman'])){
                
    $checked $_POST['schedman'];
                    if(
    $checked == 'Yes'){
            
    $desire_schedule '1';
        }
                else {
                    
    $desire_schedule '0';
                }

            
    $stop "false";
            echo 
    '<br /><div align="center">';

            
    $names1 trim($_POST['selected']);
        
    $admin2_query mysql_query("SELECT * FROM admins WHERE name = '$names1'");
        
    $admin2_data mysql_num_rows($admin2_query);
        
    $admin_query mysql_query("SELECT * FROM accounts WHERE name = '$names1'");
        
    $admin_data mysql_fetch_array($admin_query);
        
    $usname $admin_data['name'];
        
    $email $admin_data['email'];
        
    $password $admin_data['password'];
            
    $zpassword sha1($password);
        
    $mpassword md5($zpassword);
            
                if(
    $admin2_data != '0'){
                    echo 
    '<font color="red">' $usname ' is already a schedule manager, please log into the schedule manager screen to erase them from allowable schedule managers';
                    
    $stop "true";
                }
                else if(
    $stop == "false"){
                if(
    $desire_schedule == '1'){
            
    mysql_query("INSERT INTO `admins` (`username`, `password`, `email`) VALUES ('$usname', '$mpassword', '$email')");
            echo 
    '<font color="green">' $usname ' is now a schedule manager.';
            
    $stop "true";
                    }
                } else if(
    $stop == "false"){

                    if(
    $desire_schedule == '0'){
                    
    $stop "true";
                    }
                }
              }
        echo 
    '</font></div>';
    }

    ?>
    the connection to mysql is working just fine, when I put it on my site and attempt to use it, it outputs:

    Code:
    Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in update_users.php on line 77
    I tried many google searches, and have been battling this for over 12 hours (I'm not very good at PHP or mysql i guess XD)

    any input is greatly appreciated. thank you =)

  • #2
    Regular Coder
    Join Date
    Nov 2009
    Location
    Hamilton, New Zealand
    Posts
    126
    Thanks
    0
    Thanked 17 Times in 17 Posts
    Could you post the contents of line 77 in the indicated script please. I quickly reviewed your script and couldn't find any errors with the mysql_num_rows argument, so I was curious, maybe you have been looking in the wrong place?
    Affordable Web Design (New Zealand Based)
    Internet Marketing Guru
    PHP/mySQL Expert
    -------------------------------------------

  • #3
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Sounds like the query might be failing.

    Try modifying the query that you are trying to get the number of rows on like so:
    PHP Code:
    $admin2_query mysql_query("SELECT * FROM admins WHERE name = '$names1'") or die(mysql_error()); 
    That will print out the mysql error message if the query fails.
    OracleGuy

  • #4
    New Coder
    Join Date
    Jan 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks to "oracleguy" I was able to figure it out, thank you =)

  • #5
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    If you ever get an error with mysql you should use mysql_error() to work out what is wrong. It gives you a pretty good idea immediately
    Also, you should use
    PHP Code:
    $query "SELECT ... $variable ...";
    mysql_query($query); 
    This means that if your query isn't working as expected you can just use echo $query between those two lines and it will output what query is being run (when the variables have been inserted into the query)
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

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