Deleting entry from MySQL table using PHP variable

后端 未结 2 1577
情话喂你
情话喂你 2021-01-26 19:41

I\'m pretty sure this question has been asked many times, I\'ve searched the web and still can\'t figure out the solution to this problem.

Here\'s the code (I know it is

2条回答
  •  抹茶落季
    2021-01-26 20:00

    Your SQL is wrongly formatted (quotes in wrong places). I've added some comments in this improved code, check it out.

    mysql_query("SELECT * FROM testimony"); //this line is useless and you can delete it
    mysql_query("DELETE FROM transaction WHERE name = '".$testyname."'"); //this line contained wrong syntax
    

    Please note that mysql_ functions are deprecated in new versions of PHP. Check this post on more info on this subject.

    Also you might want to prevent SQL injection in the $testmyname variable. This guide will help you with tat.

提交回复
热议问题