MrBillybob Posted August 1, 2007 Share Posted August 1, 2007 I want column XY be unique so: xy | gg | zz | ee 12 | df | df | fd 13 | df | df | fd I want to enter more data but it might enter 12 | df | df | fd again so i would get an error. How would i prevent that without having to loop threw the whole database checking for that entry? Link to comment https://forums.phpfreaks.com/topic/62767-solved-data-and-mysql/ Share on other sites More sharing options...
teng84 Posted August 1, 2007 Share Posted August 1, 2007 use auto increment or query something like if (mysql_query(select * from table where field = somthing)) //the data is already used Link to comment https://forums.phpfreaks.com/topic/62767-solved-data-and-mysql/#findComment-312473 Share on other sites More sharing options...
hitman6003 Posted August 1, 2007 Share Posted August 1, 2007 If there is a second xy equal to 12, do you want it to update that row? Or change xy to be something unique? Link to comment https://forums.phpfreaks.com/topic/62767-solved-data-and-mysql/#findComment-312474 Share on other sites More sharing options...
MrBillybob Posted August 1, 2007 Author Share Posted August 1, 2007 I dont want it to auto increment i just want it to not input it Link to comment https://forums.phpfreaks.com/topic/62767-solved-data-and-mysql/#findComment-312477 Share on other sites More sharing options...
teng84 Posted August 1, 2007 Share Posted August 1, 2007 you have option 1.) query like what i did in my first post 2.) declare the field as unique if u use option 2 you will get sql error if u store same data but you can put some trick to get the error as an asset or as the conditioned material Link to comment https://forums.phpfreaks.com/topic/62767-solved-data-and-mysql/#findComment-312484 Share on other sites More sharing options...
hitman6003 Posted August 1, 2007 Share Posted August 1, 2007 Do the query like normal, but catch the error... $query = "INSERT INTO tablename (col1, col2) VALUES ('a', 'b')"; @mysql_query($query); $error = mysql_errno(); if ($error > 0 && $error == 1022) { echo "Duplicate entry skipped"; } else if ($error > 0 && $error != 1022) { echo mysql_error(); } else { echo "Added!!"; } make sure that column "xy" is a PK or has a unique index. Link to comment https://forums.phpfreaks.com/topic/62767-solved-data-and-mysql/#findComment-312491 Share on other sites More sharing options...
MrBillybob Posted August 1, 2007 Author Share Posted August 1, 2007 Thank you Link to comment https://forums.phpfreaks.com/topic/62767-solved-data-and-mysql/#findComment-312500 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.