when I try to update my database to change the location of an existing user, I receive the text in an echo which is desired but the details of a user are not changed. Here is my code - server details have been removed on purpose for privacy.
{
$server = '';
$connectionInfo = array("Database"=>"");
$conn = sqlsrv_connect($server,$connectionInfo);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
date_default_timezone_set('Europe/London');
$username = $_POST['username'];
$location = $_POST['location'];
$dateAndTime = date('d-m-y h:i a', time());
$selection_query = "SELECT 1 FROM users WHERE username = '".$username."'";
$result = sqlsrv_query($conn, $selection_query, array($username));
if (sqlsrv_fetch_array($result) == 0)
{
echo "Username does not exist.";
}
else
{
$updateUserQuery = "UPDATE users SET location='$location' datetime='$dateAndTime' where username='$username'";
sqlsrv_query($conn, $updateUserQuery);
echo $username;
echo "'s location has been successfully updated to ";
echo $location;
echo " at ";
echo $dateAndTime;
echo ".";
}
sqlsrv_close($conn);
}