Page 1 of 1
php mysql question
Posted: Wed Jan 22, 2003 11:12 pm
by smoky989
I have a form for people to enter a primary key, kind of like a password. If they enter a correct pass they can edit their info. I need a script that will check to see if the key is already being used. Any ideas.
I just need to check if it's their not insert anything or select it
Posted: Thu Jan 23, 2003 1:03 am
by m3mn0n
Code: Select all
<?
$confirmkey = mysql_query("SELECT COUNT(*) FROM $db WHERE key='$key'");
if ($confirmkey){
send to next page
} else {
send to error page
}
?>
sending can be done with
header()
Thanks
Posted: Thu Jan 23, 2003 1:12 am
by smoky989
Thanks
Posted: Thu Jan 23, 2003 1:18 am
by m3mn0n
no prob.

Still having trouble
Posted: Thu Jan 23, 2003 9:58 pm
by smoky989
I entered it in, changed the variables to my info. It won't work correctly, it's going into the if statement no matter what the variable is. The else is not being executed when the key is not in the database
Posted: Sat Jan 25, 2003 4:20 pm
by m3mn0n
try wrapping the entire thing around an if statement
eg.
Code: Select all
<?php
if($submit){
$confirmkey = mysql_query("SELECT COUNT(*) FROM $db_table WHERE key='$key'"); //db query to check for key in tables
if ($confirmkey){
send to next page
} else {
send to error page
} //ends confirmkey if
}//ends submit if
?>
and have the form send the data to a different page.
hope it works.
