jet's avatar
Level 1

SQLSTATE[HY000]: General error: 1 near ")": syntax error

am using sqlite3, and when I want to insert data to the DB it give me this error SQLSTATE[HY000]: General error: 1 near ")": syntax error please can anyone help me

here is my insert code


<?php
try{
  $db = new PDO('sqlite:./db/survey.sqlite3');

    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $sql = " INSERT INTO survey (
              fullname,
              form,
              phoneumber,
              emailaddress,
              topichated,
              difficulttopic,
              likemathstipice,
              strugglingtopic,
              enjoymathstopic,
              challenges,
              country,
              city,
            )
          VALUES ('$_POST[fullname]',
                  '$_POST[form]',
                  '$_POST[phoneumber]',
                  '$_POST[emailaddress]',
                  '$_POST[topichated]',
                  '$_POST[difficulttopic]',
                  '$_POST[likemathstipice]',
                  '$_POST[strugglingtopic]',
                  '$_POST[enjoymathstopic]',
                  '$_POST[challenges]',
                  '$_POST[country]',
                  '$_POST[city]',
                  ) ";

    // use exec() because no results are returned
    $res = $db->exec($sql);
    echo "New record created successfully";
    }
catch(PDOException $e)
    {
    echo $sql . "<br>" . $e->getMessage();
    }

$res = null;
?>
0 likes
2 replies
Snapey's avatar

I do love it when people come on a Laravel forum and post PHP code from 2005.

jet's avatar
Level 1

Please Can I get the answer or the 2021 way of doing it

Please or to participate in this conversation.