php mysql question

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
smoky989
Forum Commoner
Posts: 41
Joined: Mon Sep 02, 2002 1:14 pm

php mysql question

Post 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
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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()
smoky989
Forum Commoner
Posts: 41
Joined: Mon Sep 02, 2002 1:14 pm

Thanks

Post by smoky989 »

Thanks
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

no prob. 8)
smoky989
Forum Commoner
Posts: 41
Joined: Mon Sep 02, 2002 1:14 pm

Still having trouble

Post 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
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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. :)
Post Reply