Kumar Kumar - 1 year ago 83
PHP Question

MYSQL Error - SQLSTATE[42000]: Syntax error or access violation

I am using the below code sinppet, but getting the below error. Not sure, whats going on. I tried to print everything and it shows up fine. I tried looking for missing braces, no luck...Am I missing something ?

Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' ', ' ', '',' ', NOW())' at line 3

$nationality = $_POST['nationality'];//nationality
$vtype=$_POST['vtype'];//Visa type
$vcenter=$_POST['vcenter'];//Embassy Consulate
$vintdate=$_POST['vintdate'];//Visa Interview Date
$pstatus=$_POST['pstatus'];// Passport status
$ddate=$_POST['ddate'];//consulate decision date
$slipcolor = $_POST['slipcolor']; // Slip Color
$docsreq = $_POST['docsreq'];//documents required by consulate
$docsub = $_POST['docsub'];//documents submitted to consulate
$dsub_date = $_POST['dsub_date'];//document submitted Date
$extra_notes = $_POST['extra_notes'];// extra notes



echo "name : ".$name;
echo "nationality : ".$nationality;
echo "vtype : ".$vtype;
echo "vcenter : ".$vcenter;
echo "vintdate : ".$vintdate;
echo "status : ".$status;
echo "pstatus : ".$pstatus;
echo "ddate : ".$ddate;
echo "slipcolor : ".$slipcolor;
echo "docsreq : ".$docsreq;
echo "docsub : ".$docsub;
echo "dsub_date : ".$dsub_date;
echo "extra_notes : ".$extra_notes;

// $sql = "INSERT INTO 221gtracker (`userid`,`name`, `nationality`, `vtype`, `vcenter`, `vintdate`, `status`, `slipcolor`,`pstatus`,`ddate`,`docsreq`, `docsub`,`dsub_date`, `extra_notes`, `u_time`)
// (:userid, :name ,:nationality,:vtype, :vcenter, :vintdate, :status, :slipcolor, :pstatus,:ddate :docsreq, :docsub, :dsub_date,:extra_notes, NOW())

// status=:status_update,
// ddate=:ddate_update,
// docsreq=:docsreq_update,
// docsub=:docsub_update,
// dsub_date=:dsub_date_update,
// extra_notes=:extra_notes_update";

$sql = "INSERT INTO 221gtracker (`userid`,`name`, `nationality`, `vtype`, `vcenter`, `vintdate`, `status`, `slipcolor`,`pstatus`,`ddate`,`docsreq`, `docsub`,`dsub_date`, `extra_notes`, `u_time`)
(:userid, :name ,:nationality,:vtype, :vcenter, :vintdate, :status, :slipcolor, :pstatus,:ddate :docsreq, :docsub, :dsub_date,:extra_notes, NOW())";

$s = $pdo->prepare($sql);
$s->bindValue(':userid', $userid);
$s->bindValue(':name', $name);
$s->bindValue(':nationality', $nationality);
$s->bindValue(':vtype', $vtype);
$s->bindValue(':vcenter', $vcenter);
$s->bindValue(':vintdate', $vintdate);
$s->bindValue(':status', $status);
$s->bindValue(':slipcolor', $slipcolor);
$s->bindValue(':pstatus', $pstatus);
$s->bindValue(':ddate', $ddate);
$s->bindValue(':docsreq', $docsreq);
$s->bindValue(':docsub', $docsub);
$s->bindValue(':dsub_date', $dsub_date);
$s->bindValue(':extra_notes', $extra_notes);

Answer Source

I am assuming that it is not your intention to group your ddate and docsreq together:

:ddate :docsreq

You should probably put a comma between those.

:ddate, :docsreq
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download