Help with Error updating record:

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:


$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 = "Συμπληρώστε όλα τα παιδία";
$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>
<title>Ενημέρωση Φοιτητή</title>
<link rel="stylesheet" href="style.css">

<body style="background-color:#dfebe7;">
<div class="heading">
<h1 align=center>Ενημέρωση Φοιτητή</h1>
</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>



Why don’t you post the code using the </> button on top as it would make people trying to help you easier to do? They can’t exactly play around with the code from a picture.

Oh, I didnt know. However it appears that all of my html code isnt visible that way for some reason. First time posting here, just made the account, sorry for any trouble.

The forum software automatically operates on some of the html you include in your post, then strips out all the html tags before displaying the result.

You need to use either mark-down (I think it takes three back-ticks) or bbocde [code][/code] tags around your code. I edited your 1st post so that it is readable.

The error is most likely because there is no $id value at the time your post method form processing code is executed. You should validate the id inside your form processing code, before trying to use it as part of the sql query.

The reason there is no id is because your form isn’t doing anything to propagate the id value with the form data. I recommend that you add a hidden field with the id in it. You can also leave the action=’…’ attribute out of the form tag, in which case the browser will automatically include any existing get parameters on the end of the url when it submits the form data.

Great, thank you i fixed it.

Sponsor our Newsletter | Privacy Policy | Terms of Service