0

When my DB holds the data already it should echo "fail"

my Code is :

   if (!mysqli_query($con,"INSERT IGNORE INTO name(username, passwort, email, active, loc, image)
  VALUES ('$name', '$pass','$mail' , 0, '$loc', 'mo.png')"))
  {      

 echo "fail";
  }else{
  echo "sucess";

  }

the weird thing is if my Username ecist it do what it should do, no insert. But my echo "fail" is not called, but why?

user3369579
  • 486
  • 3
  • 7
  • 22

1 Answers1

0

Very, very simply: "insert ignore" doesn't generate an error - so your "fail" never occurs.

Suggestion: one alternative might be to try "ON DUPLICATE KEY UPDATE".

Here is the man page:

http://dev.mysql.com/doc/refman/5.6/en/insert-on-duplicate.html

Here are more details:

How do I update if exists, insert if not (AKA "upsert" or "merge") in MySQL?

Community
  • 1
  • 1
FoggyDay
  • 11,962
  • 4
  • 34
  • 48