Hi, I have a table in MySQL that I want to update it if the row exist or insert the record does not exist.
mysql_query("REPLACE INTO `$it` (file_name, directory)
VALUES ('$insert','$dir_http')"); // or die ("Insert query failed");
I was following this: http://dev.mysql.com/doc/refman/5.1/en/insert.html
But every time I run REPLACE INTO it duplicate the records instead of update/insert.
Example:
1st Time Query Execution
ID 1 Name: abc.txt
ID 2 Name: dct.txt
2st Time Query Execution
ID 1 Name: abc.txt
ID 2 Name: dct.txt
ID 3 Name: abc.txt
ID 4 Name: dct.txt
Table Structure:
mysql_query (" CREATE TABLE IF NOT EXISTS `$it`
(id int NOT NULL AUTO_INCREMENT, file_name VARCHAR(40) NOT NULL, directory VARCHAR (60) NOT NULL,
FULLTEXT (file_name), PRIMARY KEY (id) ) ") or die ("Create table query failed");