Hi everybody,,, I am facing problem, Problem is that i have a user with ic already have in my database. But my query enter another data to db when i try to enter that ic again.i want that only one ic exist in db.i make query but t only checks the format like 1234 or 5462313 not 123aa and 123333-12-1234 I want to check the format like 123456-12-1234.. My query is: // Check for existing user with the ic number $sql = "SELECT COUNT(*) FROM loguser WHERE icnumber = $ic "; $result = mysql_query($sql); if (!$result) { error('A database error occurred in processing your '. 'submission.\\nIf this error persists, please '. 'contact you@example.com.'); } if (mysql_result($result,0,0)>0) { error('A user already exists with your chosen IC Number.\\n'. 'Please try your own IC Number.'); } if (preg_match('#^[0-9]{6}-[0-9]{2}-[0-9]{4}$#', $ic)) {}else{ error('IC Number format is not Valid.\\n'. 'Please try again.'); } Code (markup): please any one has idea about it,, i think the error is here thats why it didnot check the format entered. if (mysql_result($result,0,0)>0) { Code (markup): thanks in advance
You could add a unique index for the icnumber column: ALTER TABLE `loguser` ADD UNIQUE (`icnumber`); PHP: That would give you a mysql error if when you tried to enter a duplicate.
I often use simple funda $cnt= mysql_num_rows($result); if($cnt>0) { echo "Exist"; } else { } PHP: thanks