Insert data to MySql DB and display if insertion is success or failure

前端 未结 5 1884
执念已碎
执念已碎 2020-12-10 05:09

I am inserting data to a MySQL DB, In case if the insertion fails i need to give an appropriate error message indicating so. According to my code below i will be Echo-

5条回答
  •  [愿得一人]
    2020-12-10 05:40

    if (mysql_query("INSERT INTO PEOPLE (NAME ) VALUES ('COLE')")or die(mysql_error())) {
      echo 'Success';
    } else {
      echo 'Fail';
    } 
    

    Although since you have or die(mysql_error()) it will show the mysql_error() on the screen when it fails. You should probably remove that if it isnt the desired result

提交回复
热议问题