Forum Moderators: coopster

Message Too Old, No Replies

comparing user input values in a form with database values

         

rekhad

5:43 pm on Mar 2, 2006 (gmt 0)

10+ Year Member



Hi!
I want to compare user input values in a form with my database.
Basically I want to check whether the user exits in my database.
What mysql command can do that?

jatar_k

6:54 pm on Mar 2, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



are your usernames unique? if so you can issue a select query and then test if mysql_num_rows > 0

select * from tablename where column='data'

you would obviously add your actual tablename and then the column you would like to select with and the data you have to use about your user

rekhad

7:26 pm on Mar 2, 2006 (gmt 0)

10+ Year Member



Yes name are unique.
Is this what I need to do

$firstName=$_POST["first_name"];
$query=mysql_query(SELECT * FROM table1 WHERE first_name="$firstName");
$result=mysql_num_rows($query);

jatar_k

7:36 pm on Mar 2, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I highly doubt first name will remain unique, I was referring to username or maybe even email

but

$firstName=$_POST["first_name"];
$query=mysql_query(SELECT * FROM table1 WHERE first_name="$firstName");
$result=mysql_num_rows($query);

that would work and then you can do
if ($result < 1) {

would mean that there were no rows returned and you could carry on, though you might also want to do the opposite
if ($result > 0) {
this way you can error out right away if there is a row selected and return to the user or whatever you need to do

rekhad

7:45 pm on Mar 2, 2006 (gmt 0)

10+ Year Member



How will it test whether the user exits or not?
will it go row by row and test it?

$query=mysql_query(SELECT * FROM table1 WHERE first_name=\"$firstName\"); is gving me parse error..

rekhad

7:51 pm on Mar 2, 2006 (gmt 0)

10+ Year Member



ignore my last post it was a typo error