why does this have an error???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kedora19
Forum Commoner
Posts: 34
Joined: Tue Apr 07, 2009 10:05 am

why does this have an error???

Post 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
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Re: why does this have an error???

Post 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.
kedora19
Forum Commoner
Posts: 34
Joined: Tue Apr 07, 2009 10:05 am

Re: why does this have an error???

Post 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
Post Reply