-2

My database structure

id | name | contact | location

 1 | ABC  | 012444452 | Koh

How to not insert other data into database if contact number is the same(exist) and skip.

my query

$query = mysqli_query($con, "INSERT INTO test(name, contact, location) VALUES ('$name', '$contact', '$location')");

Thanks.

Subin Chalil
  • 3,531
  • 2
  • 24
  • 38
july77
  • 673
  • 2
  • 8
  • 24

1 Answers1

3

You can use WHERE NOT EXISTS with INSERT.

"INSERT INTO test(name, contact, location)
 VALUES ('$name', '$contact', '$location') 
WHERE NOT EXISTS (SELECT * FROM test WHERE `name`= '$name')".

Hope this helps.

Subin Chalil
  • 3,531
  • 2
  • 24
  • 38
  • @Subic C Poonamgode i dont know if you still can help, but should this work with php and mysqli using mysql database? – Ingus Jun 14 '17 at 14:43