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
If that is the problem then you could try your query without the count and then use mysql_num_rows to find out whether an entry already exists.
its much easier: when you do the insert, just use "INSERT IGNORE INTO whatever...", this will only insert new values, or use "REPLACE" instead of "INSERT INTO" - depends on what you wanna do. check the mysql docs for more info about this commands.