简体   繁体   中英

Updating data in mysql php

I'm trying to update data in my database with this function

<?php
require "conn.php";
$name = $_POST["name"];
$surname = $_POST["surname"];
$age = $_POST["age"];
$username = $_POST["username"];
$password = $_POST["password"];
$mysql_qry = "UPDATE user_data (name, surname, age, username, password) values ('$name','$surname','$age','$username','$password')";
if($conn->query($mysql_qry) === TRUE) {
echo "Success!";
}
else {
echo "Something is wrong :( Error: " . $mysql_qry . "<br>" . $caonn->error;
}
$conn->close();

but it always goes to Error. Can you help me with this? I was trying to put data from keyboard but it's not working either.

I've changed this line

$mysql_qry = "UPDATE user_data SET name = '$name'";

and now it's working but its changing all the names in database and I want to change only one record...

Add WHERE id=THAT_ID and you will be fine. THAT_ID or 'THAT_ID' depending on whether the "id" field in the database is a number or text, respectively (without apostrophes if it's a number, and with apostrophes if it is a text field). Off course, change THAT_ID to whatever id you want.

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