I'm trying to update a username record, with the new one that comes from form.
After I execute the statement, a record in my database is deleted but it is NOT REPLACED with a new one, that comes from form. I can not figure out why.
index.php:
<form action="change.php">
<input type="text" name="txtNewUsername" id="txtNewUsername" placeholder="new username"><br/>
<button>Change username</button>
</form>
change.php:
<?php
session_start();
require_once __DIR__.'/connect.php';
$txtNewUsername = $_POST['txtNewUsername'];
$sUsername = $_SESSION['txtUsername'];
try{
$stmt = $db->prepare('UPDATE users SET username = :sNewUsername WHERE username = :sOldUsername');
$stmt->bindValue('sNewUsername', $txtNewUsername);
$stmt->bindValue(':sOldUsername', $sUsername);
$stmt->execute();
echo $txtNewUsername;
}catch(PDOEXception $ex){
echo $ex;
}
I would like to replace the username of connected user with the one coming from a form.