I can't seem to get the code for updating user information on my database to work. I followed a tutorial but I can't spot the error in the code. The retrieving of the information from the database works, and I am able to display that info on the page.
grep -nr '/users/myname/Desktop/website' -e "gaq"
grep -nrw '/users/myname/Desktop/website' -e "gaq"
My database is called register and my field names are id, firstname, lastname, password and email.
heres the code for my form too:
$user = $_SESSION['user_id'];
$result = $con->query("SELECT * FROM register WHERE id ='$user'");
$row = $result->fetch_array(MYSQLI_BOTH);
$_SESSION["firstname"] = $row['firstname'];
$_SESSION["lastname"] = $row['lastname'];
$_SESSION["email"] = $row['email'];
$_SESSION["password"] = $row['password'];
if(isset($_POST['update'])){
$updateFname = $_POST['fname'];
$updateLname = $_POST['lname'];
$updatEmail = $_POST['email'];
$updatePassword = $_POST['password'];
$sql = $con->query("UPDATE register SET firstname = '{$updateFname}', lastname = '{$updateLname}', email='{$updatEmail}', password='{$updatePassword}' WHERE id = $user");
header('Location:account.php');
}`
答案 0 :(得分:1)
I would add single quotes around the $user variable at the end of the update query.
答案 1 :(得分:0)
I'm assuming you left out $conn = new mysqli($servername, $username, $password, $dbname); on purpose.
ctrl.item.value