I did a post for a question PHP Login with Permission Levels that shows
how it should proceed with $POST, Mysql*, PDO, Mysqli and filter_input for better security, but, I followed your example in order to understand input, form, Hidden relationship with PHP. It would be very nice after understanding how this deletion happens, to proceed to the normalization of the encoding, as link above
In the form should contain the field text
or hidden
with the value of the code you want to send to the script PHP
perform the exclusion task via SQL
bank MySql
.
In the example I am passing you this form contains a Hidden with name id with value of 1, then by clicking the delete button it will submit the form and run the delete SQL
//Aqui o código id ta fixo (campo hidden)
<form action='deletar.php' method='post'>
<input type='hidden' name='id' value='1'>
<input type='submit' name='deletar' value='deletar' />
</form>
//Aqui você digita o código (campo text)
<form action='deletar.php' method='post'>
<input type='text' name='id' value=''>
<input type='submit' name='deletar' value='deletar' />
</form>
if (isset($_POST['id'] && is_numeric($_POST['id'])) {
$del = "DELETE FROM autoriza WHERE ID = " . $_POST['id'];
$delgo = mysql_query($del) or die('Erro ao deletar');
echo "deletado";
}
Function
mysql_
are being deprecated... Use PDO or mysqli.– planestepper
What do you mean, you want to delete a specific record without saying which one? You can explain better?
– bfavaretto
@bfavaretto: when the user sends a record through the form, it automatically generates an ID. I wanted to take this ID to put DELETE each record.
– GustavoCave
@Gustavocave It is not yet clear... You mean you just created a record but don’t know how to send it back to the corresponding delete button?
– bfavaretto
@bfavaretto exactly that!
– GustavoCave
Apparently you want to know something totally different from what you asked. Your question is about how to pass the browser id to the server. Apparently you already know how to do this, and the answer from Fccdias also explains. But what you really want to know is how to return a server ID to the browser right after creating a record. In this case it would be better to have a separate question (if you change this one, invalidates the answers you already have). Or I got it all wrong?
– bfavaretto
This is @bfavaretto. Just delete the record you are being asked for. In this case, use the registration ID to delete it.
– GustavoCave
I’ve managed to get it deleted by ID, but it’s picking up all the lines and then everything is deleted.
– GustavoCave
And I was also able to delete, but I always take the smaller ID and then delete it, regardless of which one I tried to delete.
– GustavoCave
I’m sorry Gustavo, but as much as you explain I can’t understand what you’ve done and what you can’t do.
– bfavaretto
@bfavaretto no problem! thank you for your try!
– GustavoCave