简体   繁体   English

PHP通过ID(不是名称)更新MySQL

[英]PHP update MySQL by id not name

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: PHP使用表单中的名称来更新MySQL数据库中的记录,我想使用id而不是这样的name来更新它:

<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) myfile.php >>(如果使用我的名字)

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 ? 如何使用id而不是name

You can't (at least not without JavaScript). 您不能(至少没有JavaScript)。 This has nothing to do with PHP, it's just HTML form standards .. the name attribute is the key of the value that gets sent to the server. 这与PHP无关,只是HTML表单标准.. name属性是发送到服务器的值的键。 id never gets sent, and there is nothing you can do about it. id永远不会发送,您对此无能为力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM