Hellow i am very new to php and i’m trying to do a project. I am getting this error: “Error updating record: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘’ at line 1” and i dont know how to fix it.
My code is:
<?php
$db = mysqli_connect("localhost", "root", "", "fitites");
$id = isset($_GET['id']) ? $_GET['id'] : '';
$errors = "";
if (isset($_POST['update'])) {
if (empty($_POST['AM'])or empty($_POST['Surname'])or empty($_POST['Name'])or empty($_POST['Semester'])or empty($_POST['Email'])) {
$errors = "Συμπληρώστε όλα τα παιδία";
}else{
$AM = $_POST['AM'];
$Surname = $_POST['Surname'];
$Name = $_POST['Name'];
$Semester = $_POST['Semester'];
$Email = $_POST['Email'];
$sql = "UPDATE fitites set AM='".$AM."' WHERE id=".$id;
if ($db->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $db->error;
}
mysqli_query($db, $sql);
//header('location: arxiki.php');
}
}
$fitites = mysqli_query($db, "SELECT * FROM fitites");
echo "koita to ".$id;
?>
<!DOCTYPE html>
<html>
<head>
<title>Ενημέρωση Φοιτητή</title>
<link rel="stylesheet" href="style.css">
</head>
<body style="background-color:#dfebe7;">
<center>
<div class="heading">
<h1 align=center>Ενημέρωση Φοιτητή</h1>
</div>
</center>
<br>
</div class="ena">
<form method="post" name="fitites" action="enimerosi.php" class="ena">
<?php if (isset($errors)) { ?>
<p><?php echo $errors; ?></p>
<?php } ?>
AM:<br><input type="text" name="AM"><br><br>
Επίθετο:<br><input type="text" name="Surname" class="ena"><br><br>
Όνομα:<br><input type="text" name="Name" class="ena"><br><br>
Εξάμηνο:<br><input type="text" name="Semester" class="ena"><br><br>
Email:<br><input type="text" name="Email" class="ena"><br><br>
<button type="submit" name="update" value="insert" class="ena">Ενημέρωση Φοιτητή</button>
</form>
</div>
<?php
//header("url=arxiki.php");
?>
</body>
</html>