PHP uses the name from a form to update a record in a MySQL database, I want to update it using the id not the name like that:
<form action="myfile.php" method="post">
<input type="text" name="nametextbox" id="username"/>
<input type="text" name="emailtextbox" id="email"/>
<input type="submit" name="button" id="update"/>
</form>
myfile.php >>(if I used the name)
if (isset($_POST['button'])){
$title=$_POST['nametextbox'];
$body=$_POST['emailtextbox'];
mysql_connect("x", "y", "z")or die (mysql_error());
mysql_select_db('c')or die (mysql_error());
mysql_query("UPDATE table_name SET title='$title', body='$body' WHERE `id`='$_GET[update]'");
mysql_close();
header("location:mawdoo3.php");
}
How do I used the id and not the name?
You can’t (at least not without JavaScript). This has nothing to do with PHP, it’s just HTML form standards .. the
nameattribute is the key of the value that gets sent to the server.idnever gets sent, and there is nothing you can do about it.