2
votes

I am a super rookie in programming. I am not sure why this error appears. I have searched the same question but they don't work. This is the full error:

Error: SQLSTATE[42000]: Syntax error or access violation: 1064 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 'WHERE id = '3'' at line 3

<?php

if (isset($_POST['LMedit_form'])) {

  include "db.php";

  try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $stmt = $conn->prepare("UPDATE lmreservation SET name = :name, studentstaffid = :studentstaffid, faculty = :faculty, contactno = :contactno, 
    email = :email, program = :program, participant = :participant, attandance = :attandance, module = :module, date = :date, starttime = :starttime, endtime = :endtime,
    WHERE id = :record_id");

    $stmt->bindParam(':name', $name, PDO::PARAM_STR);
    $stmt->bindParam(':studentstaffid', $studentstaffid, PDO::PARAM_STR);
    $stmt->bindParam(':faculty', $faculty, PDO::PARAM_STR);
    $stmt->bindParam(':contactno', $contactno, PDO::PARAM_STR);
    $stmt->bindParam(':email', $email, PDO::PARAM_STR);
    $stmt->bindParam(':program', $program, PDO::PARAM_STR);
    $stmt->bindParam(':participant', $participant, PDO::PARAM_STR);
    $stmt->bindParam(':attandance', $attandance, PDO::PARAM_STR);
    $stmt->bindParam(':module', $module, PDO::PARAM_STR);
    $stmt->bindParam(':date', $date, PDO::PARAM_STR);
    $stmt->bindParam(':starttime', $starttime, PDO::PARAM_STR);
    $stmt->bindParam(':endtime', $endtime, PDO::PARAM_STR);
    $stmt->bindParam(':record_id', $id, PDO::PARAM_INT);

    $name = $_POST['name'];
    $studentstaffid = $_POST['studentstaffid'];
    $faculty = $_POST['faculty'];
    $contactno = $_POST['contactno'];
    $email = $_POST['email'];
    $program = $_POST['program'];
    $participant = $_POST['participant'];
    $attandance = $_POST['attandance'];
    $module = $_POST['module'];
    $date = $_POST['date'];
    $starttime = $_POST['starttime'];
    $endtime = $_POST['endtime'];
    $id = $_POST['id'];

    $stmt->execute();

    header("Location:LMlist_reservation.php");
    }

    catch(PDOException $e)
    {
        echo "Error: " . $e->getMessage();
    }

    $conn = null;
  }
else {
  echo "Error: You have execute a wrong PHP. Please contact the web administrator.";
  die();
}

?>
2

2 Answers

1
votes

You added extra comma at the end

endtime = :endtime, WHERE id = :record_id

remove the comma after :endtime

endtime = :endtime  WHERE id = :record_id 
1
votes

Remove comma after endtime= :endtime and before WHERE in $stmt string:

    $stmt = $conn->prepare("UPDATE lmreservation SET name = :name, studentstaffid = :studentstaffid, faculty = :faculty, contactno = :contactno, 
    email = :email, program = :program, participant = :participant, attandance = :attandance, module = :module, date = :date, starttime = :starttime, endtime = :endtime
    WHERE id = :record_id");