I am trying to make an update in Mysql with php. I wrote the following:
include "db.php";
function cliffhangers(){
global $connection;
$query = "SELECT * FROM users ";
$result = mysqli_query($connection, $query);
if (!$result) {
die('Query FAILED' . mysqli_error());
}
while($row = mysqli_fetch_assoc($result)){
$id = $row['ID'];
echo "<option value = 'id'>$id</option>";
}
if(isset($_POST['submit'])){
$email = $_POST['email'];
$password = $_POST['password'];
$id = $_POST['cliffhangers_id'];
$query = "UPDATE users SET email = '$email', password = '$password' WHERE ID = $id ";
$result = mysqli_query($connection, $query);
if (!$result) {
die('Query FAILED' . mysqli_error($connection));
}
}
and I am getting the following syntax error:
Query FAILEDYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
What am I doing wrong?
I expected for the email and password to update, but I am getting the syntax error instead.