Filipino Trends 2017
Filipino Trends 2017

Reputation: 53

Check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE id ='2'' at line 4

I have a problem with my UPDATE code. It gives me this error:

Update Failed!! 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 ='2'' at line 4

I'm searching online and I cant find any solution to my problem.
THIS IS MY UPDATE CODE:

<?php

    include('db.php');
    $id = $_GET['id'];
    if (isset($_POST['id'])){

    $sql = "UPDATE tbl_student SET stud_id ='".$_POST['stud_id']."',
                                    fullname ='".$_POST['fullname']."',
                                    course ='".$_POST['course']."',
                                    WHERE id ='".$_POST['id']."'";

    $result = $conn->query($sql) or die ("Update Failed!!" . $conn->error);

    header("location: index.php");
    }

    else {
        echo "ERROR" . $conn->error;
        header ("location: update.php");
    }

?>

Upvotes: 0

Views: 3306

Answers (1)

B. Desai
B. Desai

Reputation: 16446

You have added , at last after course . Remove it. Change your query to:

$sql = "UPDATE tbl_student SET stud_id ='".$_POST['stud_id']."',
                                    fullname ='".$_POST['fullname']."',
                                    course ='".$_POST['course']."'
                                    WHERE id ='".$_POST['id']."'";

Upvotes: 1

Related Questions