...

View Full Version : Check if variable exisist in db



zubat
01-07-2012, 09:13 AM
Hello,

i got some problem with my code there i wanna check if a variable exsist and if it does it should do a function and if not it should just send back an echo that the variable din't exisist.



$search = "SELECT code FROM pw WHERE code='".$code."'";
$result = mysql_query($search) or die ('SQL Error: '. mysql_error());
if (mysql_num_rows($result) > 0)
{
//Do the function
}
else
{
echo "Code was wrong";
}


i get error on the $search row and i don't know, the database is named "eric" the table is "pw" and the codes row name is "code" and the name on the $_POST code they send in on the form page is code also.

//Zubat

sunfighter
01-07-2012, 05:27 PM
You should give us the error.
your 'looks' OK to me. Maybe your not connected to the DB. Don't know without the error message.

zubat
01-08-2012, 12:47 AM
You should give us the error.
your 'looks' OK to me. Maybe your not connected to the DB. Don't know without the error message.

I get the error


Notice: Undefined variable: code in /home/eric/public_html/vip/check.php on line 11 Din kod var felaktig

On the page when i send the nick and code from the form page.

sunfighter
01-08-2012, 05:01 PM
The error says "Undefined variable:" And the line
$search = "SELECT code FROM pw WHERE code='".$code."'"; has only one variable,
$code. So I'm guessing the code prior to what you gave us is not getting $code equal to anything. Fast check would be to A) run an echo on the 'search' string

echo $code;die;just before the above 'search =' line or put

$code = 'put something here' just before the above 'search =' line.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum