cjosephson Posted August 7, 2007 Share Posted August 7, 2007 I am trying to add rows to my database via an online form, and when I submit it, even if my value for a column is the exact same as in a previously existing entry, the new value is considered unique. I have mysql server version 5.0.38, and the command I am using is $query = "insert into allsw2 (keyname, name, location, binder_or_shelf, row, number) values ('$GLOBALS[newkey]', '$name', '$location', '$binder', '$row1', '$number')"; mysql_query($query); I have an online form to add entries to my database. I collect the variable, and trim whitespace from it using this code: $number = trim($_POST['number']); Unfortunately, something is remaining, and when I add an entry that has the same value in the number column as a previously existing entry, it is treated like a different number! I use this command to select distinct records: "select distinct number from allsw2 order by (number+0)". Also, my data type for the column is varchar (I do entries like '1 thru 8', so this is necessary). Why is my number showing up twice? Is there something else I need to do to the variable before I put it into the table? Quote Link to comment https://forums.phpfreaks.com/topic/63721-unwanted-duplication/ Share on other sites More sharing options...
fenway Posted August 10, 2007 Share Posted August 10, 2007 Well, if you want mysql to do this, you need a UNIQUE index. Quote Link to comment https://forums.phpfreaks.com/topic/63721-unwanted-duplication/#findComment-320452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.