Question:
MySQL Query in PHP - Checking duplicates?
Spyker73
2008-12-23 08:43:29 UTC
I have something in my website where you pick a name, but I need it to check if the name isn't taken, so how would I use a MySQL query to check what the user typed in. Something like ...

$namecheck = *MySQL query here*

if($namecheck = 0)
*make account*
else
*give error*

Thats basically how my code is
Three answers:
anonymous
2008-12-23 08:49:58 UTC
Assuming the table where you store the name is users, containing a field 'name' where you store the name, and a field 'id' that contained the record id:



SELECT id FROM users WHERE name=$name;



If a record is found, the name was already in use.
?
2016-10-18 07:14:31 UTC
i can't see all your source code, yet i will supply it a attempt.... a million. the 1st project i might do is to get the comprehensive style of records you have interior the database. you're able to try this by using calling a question something like: 'pick count variety([your_primary_field]) as numrecs from tutorials' ... $numofrecs = $row['numrecs']; 2. determine on what proportion records you pick to coach on an internet site. so in case you 'numrecs' is 31, and you pick 10 in step with website, you will choose say 4 pages. perfect? $recperpage = 10; $numberofpages = ceil ($numofrecs/$recperpage); 3. you may desire to get yet another variety that's the beginning factor the place you pick to commence counting the subsequent '$recperpage' records. the way you will artwork that out is by using.. $starting_record = ($current_page_num* $recperpage)+a million; so in case you're on website 3, you have performed (3*10)+a million records, for this reason your starting_record is thirty first record. 4. you may then adjust your pick assertion to apply minimize sources.... pick * FROM tutorials the place subcat = '$sub' and status='2' minimize $starting_record, $recperpage; desire that gets you all started. it isn't the cleanest of codes, even nevertheless it is going to do.
gajendra d
2008-12-23 09:29:59 UTC
$namecheck=mysql_query("select * from user where name=$x");

if($namecheck!=NULL)

{

make account

}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...