Results 1 to 3 of 3
Hi
I how can I prevent duplicate enteries in mysql database.
I set slim browser to auto refresh every second, as I was hit n trying
codes, learning my myself ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-12-2008 #1Linux Newbie
- Join Date
- Aug 2005
- Posts
- 213
how to prevent duplicate enteries
Hi
I how can I prevent duplicate enteries in mysql database.
I set slim browser to auto refresh every second, as I was hit n trying
codes, learning my myself from online sites.
suddenly i saw in phpmyadmin theat there were 44 duplicate entries already. Ho can i make an error appear if similar entry exists.
PHP Code:<?php
include 'conn.php';
//create table record
mysql_query
("CREATE TABLE record(
id INT AUTO_INCREMENT NOT NULL,
names VARCHAR (33),
pwd1 VARCHAR(44),
pwd2 VARCHAR(33),
email VARCAR (33),
notes VARCHAR (99))");
echo '<br>';
echo 'table record created!!';
?>Cool Surfer - Registered linux user #397629
- 10-12-2008 #2Linux Enthusiast
- Join Date
- Apr 2004
- Location
- UK
- Posts
- 678
You don't say how many columns need to match to be a duplicate, but it looks like a table of users so I'd assume duplicates mean two records with the same name.
From the Mysql documentation
I've not tested this code because I don't have mysql handy, but if it doesn't work then you can refer to the documentation to fix it up.Code:CREATE TABLE record( id INT AUTO_INCREMENT NOT NULL, names VARCHAR (33), pwd1 VARCHAR(44), pwd2 VARCHAR(33), email VARCAR (33), notes VARCHAR (99), primary key(names))
This puts a primary key index on the names colmun, requiring that the field be populated and unique. If you try to put in another record with a duplicate name then it will raise a primary key violation error and prevent you from doing it.
Let us know how you get on,
Chris...To be good, you must first be bad. "Newbie" is a rank, not a slight.
- 10-12-2008 #3Linux Newbie
- Join Date
- Aug 2005
- Posts
- 213
Thanks, it seems logical n should work. Will try it.
Cool Surfer - Registered linux user #397629


Reply With Quote
