Jump to content

duplicate records


vang163

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.