I am trying to create a form to update the users details stored in the database, but I am getting an error Parse error: syntax error, unexpected '"' in update.php on line 18
. Im trying to say Update the user with the username that matches the session (the session stores the username) Im not sure why its wrong because i've used the comparison to session username before and it worked fine. also will I have to then update the session with the new username??
update.php
<?php
session_start();
function updateAccount(){
$pdo=new PDO('mysql:host=localhost;dbname', 'name', 'password');
$name=$_POST['Name'];
$surname=$_POST['Surname'];
$email=$_POST['Email'];
$username=$_POST['Username'];
$password=$_POST['Password'];
//Execute the query
$hashPass = hash('sha512', $password);
$st = $pdo->prepare('UPDATE Users SET Name = :Name, Surname = :Surname, Email = :Email, Username = :Username, Password = :Password WHERE Username = '".$_SESSION['userName']."'');
if(!isset($error)){
//no error
$st->execute(array('Name' => $name, 'Surname'=>$surname, 'Email'=>$email, 'Username'=> $username, 'Password' => $hashPass));
header("Location: user.php");
}else {
echo "Error";
}
}
}
if(isset($_POST['update'])){
newAccount();
}
?>
Form where users enter details (not sure this makes a difference)
<form id="update" method="post" action="update.php">
<h2>Account Update:</h2>
<br>Name:
<input type="text" name="Name" placeholder="Name">
<br>Surname:
<input type="text" name="Surname" placeholder="Surname">
<br>Email:
<input type="email" name="Email" placeholder="Email">
<br>Username:
<input type="text" name="Username" placeholder="Username">
<br>Password:
<input type="password" name="Password" placeholder="Password">
<br>Re-enter Password:
<input id="pass2" type="password" name="Password_check" placeholder="Password Check">
<br><input id="updates" type="submit" name="update" value="Update"> <br>
</form>