vang163 Posted July 13, 2008 Share Posted July 13, 2008 hi, i want to edit a row of record and make sure that it does not create duplicate data in database when updating. i've managed to extracted the row of data and display it in a table format. all the extracted data is displayed in each textbox field in the table format. here come my problem: i did not edit the data, the id number remains the same without change, when i press the 'update data' button, i cannot update this row of record as the error message display "user id already in use". below is my code: $query = "SELECT count(*) AS c FROM $table WHERE userid='$userID'"; $result = mysql_query($query) or die("Query failed"); $result_array = mysql_fetch_assoc($result); if($result_array['c'] > 0) { echo 'user ID already in use'; } this code help me to prevent duplicate ID, but it is also preventing me from updating my data. can someone show me how to work around this, thanks. Link to comment https://forums.phpfreaks.com/topic/114502-duplicate-records/ Share on other sites More sharing options...
chronister Posted July 13, 2008 Share Posted July 13, 2008 If your doing and update rather than in insert, then there should be no chance of this error..... when updating you will use a WHERE userid='$userID' Your id check code will tell you if your trying to insert a duplicate userid, but if your updating then that code does not need to run as it will be an UPDATE instead of a INSERT. Hope this helps... if not, then post more code. Link to comment https://forums.phpfreaks.com/topic/114502-duplicate-records/#findComment-588813 Share on other sites More sharing options...
vang163 Posted July 13, 2008 Author Share Posted July 13, 2008 hi, thanks, i've managed to solve it myself. Link to comment https://forums.phpfreaks.com/topic/114502-duplicate-records/#findComment-588835 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.