简体   繁体   English

更新MYSQL数据库OOP PDO

[英]Updating MYSQL database OOP PDO

I recently created a website.我最近创建了一个网站。 I followed some guides to get Login Registration with Email Verification, Forgot Password using PHP.我按照一些指南使用电子邮件验证进行登录注册,使用 PHP 忘记密码。 (LINK Login Registration with Email Verification, Forgot Password using PHP. PDO OOP ) 使用电子邮件验证链接登录注册,使用 PHP 忘记密码。PDO OOP

NOW I want them to be able to select a number from 0-9999 and then save this value to a column in the users database.现在我希望他们能够从 0-9999 中选择一个数字,然后将此值保存到用户数据库中的列中。 I am stuck as to how to do this.我不知道如何做到这一点。

Here is a picture of the layout and some settings I have so far.这是布局的图片和我到目前为止的一些设置。

AS YOU CAN SEE, I JUST NEED THE INPUT FIELDS SAVED TO THE CORRECT COLUMN LIKE I HAVE THE FIRST ONE OWRATING WHEN THE SAVE BUTTON IS PRESSED如您所见,我只需要将输入字段保存到正确的列中,就像按下保存按钮时我的第一个字段一样

Thank you so much for your time.非常感谢您的参与。

First, you need to give a name attribute for your <input> form fields.首先,您需要为<input>表单字段提供name属性。 This name is how you will fetch the value.此名称是您获取值的方式。

<input type="number" name="owrating" value="0">

How to get a value from a form submission:如何从表单提交中获取值:

$owrating = (int) $_POST['owrating']

How to update a MySQL table with the value:如何使用值更新 MySQL 表:

$sql = "UPDATE tbl_users SET owrating = :owrating WHERE id = :userID";
$stmt = $conn->prepare($sql);
$stmt->execute(['owrating'=>$owrating, 'userID'=>$userID]);

Please get into the habit of using query parameters instead of copying PHP variables into your SQL strings.请养成使用查询参数的习惯,而不是将 PHP 变量复制到 SQL 字符串中。 If you put your code on the internet, you need to learn how to defense against SQL injection attacks.如果你把你的代码放到互联网上,你需要学习如何防御 SQL 注入攻击。 You might like my presentation SQL Injection Myths and Fallacies .您可能会喜欢我的演示文稿SQL 注入神话和谬误

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

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