PHP/MYSQL remove row by id -
I have a form that asks the user to enter the examination ID that they want to remove from the exam table in DB Are there.
I have the problem that the user enters the ID, which does not match in the DB, the script seems to ignite the other situation completely ignoring the fire.
I may have implemented this wrong but as far as I know I can not see where I am wrong, but I suspect that if anything wrong in my case Has happened.
This is my form for which the user needs to enter the exam ID to delete
& Lt; Div class = "formContent" & gt; & Lt; = "Id" for labeL & gt; Id & lt; / LabeL> & Lt; Input type = name of text = "id" square = "input" & gt; & Lt; Br> & Lt; Br> & Lt; Br> & Lt; Br> & Lt; Br> & Lt; Input type = "submit" value = "delete" & gt; & Lt; / Div & gt; & Lt; / Form & gt; `
This function has passed which contains the SQL query to delete the record from the table
& lt? Php included ('dbLogin.php'); $ Id = trim ($ _ POST ['id']); If ($ id! = "") {$ Delete = "Where to delete id = '$ id'"; $ Result = mysql_query ($ delete); If (! $ Result) {dead ("can not delete data from database!" + Mysql_error ()); Echo & lt; Br> & Lt; Br> '; Echo & lt; A href = "home.html" & gt; Return & lt; / A & gt; '; } Else {echo "test: $ id has been removed"; }} Else {resonant "no data entered!" Mysql_error (); }? & Gt;
As you ! See the $ result
condition, it is saying that if the record is not present, delete the query and confirm the deletion. Is there any obvious reason that if there is population in the situation then? > The statement is not considered successful, even if no line has been removed. (How does SQL work in general, this is not MySQL-specific.)
I would say that you should know how many rows were deleted, but as the others have said.
This is highly sensitive to SQL injection attacks as your code. If someone had to post the following ID for the examination DEATED. FP (Remember, they do not have to use your form to do so, so any client-side check can be bypassed):
'or 1 = 1 or id ='
... I think it should probably delete every exam in your table, because your SQL statement The end will be:
Where to remove exams id = ' 'Or 1 = 1 or id =' '
... which is a valid delta statement, where it matches all its rows.
Parameter queries (available in non-excluded MySQL drivers like mysqli or PDO) will counter this problem.
Comments
Post a Comment