简体   繁体   中英

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. (LINK Login Registration with Email Verification, Forgot Password using 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. 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. 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:

$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. If you put your code on the internet, you need to learn how to defense against SQL injection attacks. You might like my presentation SQL Injection Myths and Fallacies .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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