mmarif4u Posted January 6, 2007 Share Posted January 6, 2007 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 icagain.i want that only one ic exist in db.i make query but t only checks theformat like 1234 or 5462313 not 123aa and 123333-12-1234I want to check the format like 123456-12-1234..My query is:[code] // 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 [email protected].'); } 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]plz any one has idea about it,,i think the error is here thats why it didnot check the format entered.[code]if (mysql_result($result,0,0)>0) {[/code]Thanks in advance.. Link to comment https://forums.phpfreaks.com/topic/33052-solved-how-to-prevent-multiple-entries-to-db/ Share on other sites More sharing options...
HoTDaWg Posted January 6, 2007 Share Posted January 6, 2007 perhaps it would help if you showed us your database structure? Link to comment https://forums.phpfreaks.com/topic/33052-solved-how-to-prevent-multiple-entries-to-db/#findComment-153989 Share on other sites More sharing options...
mmarif4u Posted January 6, 2007 Author Share Posted January 6, 2007 Actully i have two tables..This is access table:[code]CREATE TABLE `access` ( `icnumber` varchar(45) default NULL, `acccode` varchar(45) default NULL, `actdate` varchar(45) default NULL, `expdate` varchar(45) default NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1;[/code]this is loguser table:[code]CREATE TABLE `loguser` ( `id` int(10) unsigned NOT NULL auto_increment, `icnumber` varchar(45) default NULL, `username` varchar(45) default NULL, `fullname` varchar(45) default NULL, `hp` varchar(45) default NULL, `email` varchar(45) default NULL, `password` varchar(45) default NULL, `creationdate` varchar(45) default NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1;[/code] Link to comment https://forums.phpfreaks.com/topic/33052-solved-how-to-prevent-multiple-entries-to-db/#findComment-153992 Share on other sites More sharing options...
mmarif4u Posted January 6, 2007 Author Share Posted January 6, 2007 Can i anyone have how to store on value to db then later ifa user want to insert with that value error msg showed to userthat this value already exits. here value is ic. Link to comment https://forums.phpfreaks.com/topic/33052-solved-how-to-prevent-multiple-entries-to-db/#findComment-154021 Share on other sites More sharing options...
Vampen Posted January 6, 2007 Share Posted January 6, 2007 Not sure if this is what you mean, but here is how I prevent others users from making the same unsername:[code]$tilkobling = CONNECT("USER"); $sql = "SELECT * FROM USER WHERE USERNAME='$_USERNAME'"; $resultat = mysql_query($sql, $tilkobling); $rad = mysql_fetch_array( $resultat );if($rad['USERNAME'] == ' '){mysql_query ("INSERT INTO USER (USERNAME) VALUES ('$_USERNAME'')");echo "<br><br><b>SUCKSESS!</b><br>";}else{echo "<br><b>USERNAME TAKEN!!</b><br>";}}[/code] Link to comment https://forums.phpfreaks.com/topic/33052-solved-how-to-prevent-multiple-entries-to-db/#findComment-154180 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.