Page 1 of 1

Validate a number against database

Posted: Wed Apr 21, 2010 9:44 am
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

Re: Validate a number against database

Posted: Wed Apr 21, 2010 10:43 am
by social_experiment
Depending on your form's "method", it would be $_POST or $_GET.
$payee = $_POST['payee'] || $payee = $_GET['payee']

Re: Validate a number against database

Posted: Thu Apr 22, 2010 7:19 am
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 :)

Re: Validate a number against database

Posted: Thu Apr 22, 2010 7:35 am
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?