0

enter image description here

I want to disable a mysql insert if two rows have same values. For Example: If at row 1 title="title1" & url="www.example.com" AND also at row 2 title="title1" & url="www.example.com" I want only the first row to be inserted.

FOUND THE ANSWER:

ALTER TABLE `my_table` ADD UNIQUE `unique_index`(`column1`, `column2`);
Krishnadas PC
  • 5,981
  • 2
  • 53
  • 54
  • 2
    possible duplicate of [How do I specify unique constraint for multiple columns in MySQL?](http://stackoverflow.com/questions/635937/how-do-i-specify-unique-constraint-for-multiple-columns-in-mysql) – Machavity Mar 23 '15 at 12:12
  • use unique key as title will serve your purpose – rohitr Mar 23 '15 at 12:51

1 Answers1

1

Before inserting data fire Select query as

$s1 = "Select * From your table where title = '$title' and URL = '$URL'";

 $res = mysql_query($s1) or die("!query");

 if(mysql_affected_rows ())
 {
   echo "record exists";
  }
 else
 {
 echo "your insert query";
  } 
rohitr
  • 371
  • 2
  • 11