Page 1 of 1

why does this have an error???

Posted: Mon May 11, 2009 8:02 pm
by kedora19
i have this as my code

Code: Select all

 
<?php
                include '../login/dbc.php';
  
                //first open connection to your database
                
                $takeuser = mysql_query("SELECT * FROM users WHERE id='$_SESSION[id]' AND activated='1'"); //Right now script check id number from url against the database
                if (mysql_num_rows($takeuser) < 1) { //checks if we have that id number in our database
                    echo "You Have No Friends...Better Get Some"; //inform the user that we found 0 result
                    } else { //or if we found some
                while ($row=mysql_fetch_array($takeuser)) { //Taking the result set
                    echo 'Name: ' . $row['friendname'] . '<br/><hr/><br/>'; //Displaying the result (ie you can have various fields in your table, display what you want)
                    } //closing the loop
                    } //closing the "if" statement
  
 
                    mysql_close($link); //and then we close connection
?>
 
i have start session at the top of my page but didn't include it.

but it comes up the error as "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource"
even though i've used this before.

any help would be appreciated, Kedora19

Re: why does this have an error???

Posted: Mon May 11, 2009 8:12 pm
by SidewinderX
Your query probably failed. Try

Code: Select all

$takeuser = mysql_query("SELECT * FROM users WHERE id='$_SESSION[id]' AND activated='1'") or die(mysql_error());
and see if it spits out an error.

Re: why does this have an error???

Posted: Mon May 11, 2009 8:42 pm
by kedora19
SidewinderX wrote:Your query probably failed. Try

Code: Select all

$takeuser = mysql_query("SELECT * FROM users WHERE id='$_SESSION[id]' AND activated='1'") or die(mysql_error());
and see if it spits out an error.
thanx now it works, don't know why i didn't think of it
Kedora19