search

Home  >  Q&A  >  body text

php - Error display after inserting duplicates after unique key is set

How to change the database error prompt to js?
Use if (insert statement) {echo "<script>alert('This data already exists')</script>"}
insert If the statement encounters a duplicate unique key, it will not return false but directly display a database error

伊谢尔伦伊谢尔伦2809 days ago423

reply all(4)I'll reply

  • ringa_lee

    ringa_lee2017-05-16 13:08:49

    try catch I usually set a unique primary key and check to see if there are duplicates before inserting

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-16 13:08:49

    insert ignore into ·table· ...plus ignore

    reply
    0
  • 迷茫

    迷茫2017-05-16 13:08:49

    try catch

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 13:08:49

    try
    { //...}
    catch(Exception $e)
    { //...}

    reply
    0
  • Cancelreply