Jump to content

Prevent Duplicate Entrie


CosminStan

Recommended Posts

Heloo guys i have a problem wit a script

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'root';
$dbname = 'site';
 $con = mysql_connect($dbhost, $dbuser, $dbpass);
   if (!$con)
   {
   die(mysql_error());
   }
 mysql_select_db($dbname, $con);
  $sql = "REPLACE INTO stiri (id, titlu, continut, link, categorie, data) VALUES ('','$titlu','$text','$link','Liga 1','$data')"; 
  mysql_query($sql);
 mysql_close($con);

This part is in a php foreach part and every time i run the script i get duplicate entrie, how can i solve this. Thx!

Link to comment
https://forums.phpfreaks.com/topic/270690-prevent-duplicate-entrie/
Share on other sites

It does not matter whether you use REPLACE or INSERT...IGNORE, the only way that MySQL knows an item is an unwanted duplicated is to set those columns that cannot be duplicated as UNIQUE.

 

If you don't want to to do that then it up to you to validate that items do not already exist. Am I getting through?

 

BTW - if you are storing dates in "j M Y" format then it is as much use as a chocolate teapot.

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.