Validate a number against database

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
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Validate a number against database

Post by nite4000 »

Hey all

I am trying to figure how to take a number entered in a form and check it against the database

The table name is members and field is acct_num

If they enter an account number in the form and submit it and it dont exist it should come back saying invalid account number otherwise it will go through

I have tried everything i know SHOULD work but no luck. Anyone who can tell me how would be nice.

Here is what I have

Code: Select all

 $checkuser = "SELECT acct_num FROM members WHERE acct_num='$payee'"; //$payee is the variable for textbox payee
$query = mysql_query($checkuser); 

if ( mysql_num_rows($query) > 0 ) { 
$chk=TRUE;
$msg ="Invalid Account Number."; 
}  
Thanks
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Validate a number against database

Post by social_experiment »

Depending on your form's "method", it would be $_POST or $_GET.
$payee = $_POST['payee'] || $payee = $_GET['payee']
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
dmsundar
Forum Newbie
Posts: 5
Joined: Thu Apr 22, 2010 7:01 am

Re: Validate a number against database

Post by dmsundar »

hey,

if number of rows is greater than 0 then why should there a msg like 'Invalid account number'

Need more of your code to identify the prob...






________________________________________________________
The Best Way out is always through :)
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Validate a number against database

Post by social_experiment »

Im also slightly confused by your question now : Are you having a problem with the type of reply i posted OR are you have a problem with creating a query to check the value?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply