Monday 15 June 2015

php - Mysqli DELETE not working with variable -


I use direct kudanga php in it. If I use a variable as the value, There is a problem deleting the record. The line of code given below works perfectly. "mysqli_query" ($ con, "Remove from high score WHERE name = 'David'");

But the name of the user will change, so I need to declare this as a variable. I have tried all kinds of variations but nothing seems to work. My latest unsuccessful attempt was the code below, which I declare as a variable when I am involved.

  mysqli_query ($ con, "Remove from high score WHERE name = '{$ name}'");    

In such circumstances, it is good to check that there really is something in variables Which is the service you expect me to And I also find that echoing the entire query string is a good way to find out why a query is not working.

  $ sqlquery = "Remove from high score WHERE name = '{$ name}'"; // puts a glance on the query ... resonates "pre & gt; $ sqlquery "; // use it ... mysqli_query ($ conn, $ sqlquery);   

I should warn you that if the $ name comes from an untrustworthy, such as publicly viewable HTML form, then it needs to be 'safe' before using it in the query Consider this ''. Once you know that your code is correctly making its footprints, make sure it has been protected before putting it in your query.

No comments:

Post a Comment