Jump to content

[SOLVED] PHP fetches MySQL table


WhiteCube

Recommended Posts

hi!

 

I have this code

 

 $result = mysql_query("SELECT * FROM rpg_user
WHERE username = '$username'") or die(mysql_error());

 

which finds the row in my table which matches my $username variable..

 

However.. sometimes.. it's not there.. What code can i use to tell me so?

 

something like

 

if($username does not exist in row){

  echo "does not exist"

}else{

  echo "does exist"

}

 

can someone write up a simple script for me?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/80986-solved-php-fetches-mysql-table/
Share on other sites

you can use mysql_num_rows function for that below is an example

 

$result = mysql_query("SELECT * FROM rpg_user WHERE username = '$username'") or die(mysql_error());
$num_rows = mysql_num_rows($result);

if ($num_rows > 0)
{
echo "exists";
}
else
{
echo "does not exists"';
}

 

hope its helpful

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.