SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Checking for matching record in MySQL table

We can just check MySql table to verify whether a record exist or not. Here we are not interested in collecting the actual data from table. We are interested in getting a reply of TRUE or FALSE from our command. We will try for one line command using PHP.

We need such a query while working on a member signup script. Here when member enters a userid in the signup form we need to verify with our existing table to know if the userid is already used by some other member. Some time we will have different pages with access to different groups of members ( here the members have different level of access ). So when the member visit a page we will check with our table the member has required level of privilege or not.

This conditional checking is done by using if condition in PHP. Let us see the code for checking the userid exist inside a MySQL table or not.

if(mysql_num_rows(mysql_query("SELECT userid FROM plus_signup WHERE userid = '$userid'"))){
// Code inside if block if userid is already there
}

The above sql query will return TRUE or FALSE depending on the presence of userid in MySQL table.


Omar19-02-2010
Thank you,
That helped Me ..
Vinayak06-03-2010
Thanks, the code solved the bug in my program.
Danoj23-03-2010
Thank you very much for the code, its very important code to all programmers.
Elise02-06-2010
Wauw!! I was searching for this code for hours!! Thank you so much!!
laan08-07-2010
you rule that was exactly what i was looking for 3 second google search and blam on with the programming
Sashko13-07-2010
Awesome! Concise and accurate.
Jan09-12-2010
Thanks, I used to use the mysql COUNT function for this but this is much handier !
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked


Join Our Email List
Email:  
For Email Newsletters you can trust
SQL Tutorial List
SQL Commands
SQL Sections
Date & Time
Join Table
String
Math