Jump to content

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

no surprises there then.

 

You could wait for MySQL v6 - believe it will have a built-in clairvoyance feature so it will detect duplicates without you telling it which column should be unique.

Edited by Barand

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.

Edited by Barand
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.