hi everyone,
i have to delete the data from the database.but there is one problem, when i checked any checkbox,all data are deleted from database.here is my code.please help me.
Also, it should be noted that it's often not recommended to look for a submit button in your submission processing as it's possible to submit forms without using the button.
Do not use $_SERVER['PHP_SELF'], it contains user input. Use "#" in this case instead.
When your code is displaying text input boxes named "t," it is deleted those records.
Your code can produce any number of check boxes. Each is named the same and contains the same value in your form. How do you know which record to delete? If multiple check boxes are selected, only the last will be seen by your script. This is due to your choice in naming the field "chk" as opposed to "chk[]" or similar.
The following is an assignment. You want a equality check: ==$_POST['Submit'] = 'Delete'
Also, it should be noted that it's often not recommended to look for a submit button in your submission processing as it's possible to submit forms without using the button.
Do not use $_SERVER['PHP_SELF'], it contains user input. Use "#" in this case instead.
When your code is displaying text input boxes named "t," it is deleted those records.
Your code can produce any number of check boxes. Each is named the same and contains the same value in your form. How do you know which record to delete? If multiple check boxes are selected, only the last will be seen by your script. This is due to your choice in naming the field "chk" as opposed to "chk[]" or similar.
hi,
i make all changes as you said.but when i check any checkbox all checkboxes are selected automatically and following codes are not execute.
$_POST['chk'] will be an array. The elements will not contain any specific information to associate them with an ID as you are using "off" as their value. "on" will not be any of the elements.