php - Number of bound variables does not match number of tokens with PDO -
i running through errors displayed in this post since 2 days.
here response var_dump($_post)
:
array (size=5) 'select_old' => string '2' (length=1) 'patient_name' => string '' (length=0) 'app_date' => string '2016-03-07' (length=10) 'app_time' => string '11:11' (length=5) 'app_reason' => string 'a' (length=1)
and here error got:
exception 'pdoexception' message 'sqlstate[hy093]: invalid parameter number: number of bound variables not match number of tokens' in c:\wamp\www\dentist\pages\add_appoint.php:35 stack trace:
0 c:\wamp\www\dentist\pages\add_appoint.php(35): pdostatement->execute() #1 {main}
here php code:
<?php //set error reporting on error_reporting(e_all); ini_set("display_errors", 1); //include connection file require_once('../include/global.php'); //json , php header header('content-type: application/json'); $user = $_session['username']; $id_logged = $_session['login_id']; try { $arr = array(); //values ajax $patient_name = $_post['patient_name']; $date_app = $_post['app_date']; $time_app = $_post['app_time']; $reason = $_post['app_reason']; $old_patient_id = $_post['select_old']; //var_dump($_post);exit(); //if new patient if($patient_name == "" && $old_patient_id != 0) { //see if date , time exist $appexist = "select * appointment id_logged = :id_logged , date_app = :date_app , time_app = : time_app"; $appexiststmt = $conn->prepare($appexist); $appexiststmt->bindvalue(":id_logged", $id_logged); $appexiststmt->bindvalue(":date_app", $date_app); $appexiststmt->bindvalue(":time_app", $time_app); $appexiststmt->execute(); $appexiststmtcount = $appexiststmt->rowcount(); if($appexiststmtcount === 0) { //add appointment table $appadd = "insert appointment(id_logged, patient_id, date_app, time_app, reason) values(:id_logged, :patient_id, :date_app, :time_app, :reason)"; $appaddstmt = $conn->prepare($appadd); $appaddstmt->bindvalue(':id_logged', $id_logged); $appaddstmt->bindvalue(':patient_id', $old_patient_id, pdo::param_int); $appaddstmt->bindvalue(':date_app', $date_app); $appaddstmt->bindvalue(':time_app', $time_app); $appaddstmt->bindvalue(':reason', $reason); $appaddstmt->execute(); echo "added"; } else { echo "not added"; } } //if patient name exist if($patient_name != "" && $old_patient_id == 0) { //add new patient $addnewpatient = "insert patient(patient_name, id_logged) values(:patient_name, :id_logged)"; $addnewpatientstmt = $conn->prepare($addnewpatient); $addnewpatientstmt->bindvalue(":patient_name", $patient_name); $addnewpatientstmt->bindvalue(":id_logged", $id_logged); $addnewpatientstmt->execute(); $lastid = $conn->lastinsertid(); //see if date , time exist $appexist = "select * appointment id_logged = :id_logged , date_app = :date_app , time_app = : time_app"; $appexiststmt = $conn->prepare($appexist); $appexiststmt->bindvalue(":id_logged", $id_logged); $appexiststmt->bindvalue(":date_app", $date_app); $appexiststmt->bindvalue(":time_app", $time_app); $appexiststmt->execute(); $appexiststmtcount = $appexiststmt->rowcount(); if($appexiststmtcount == 0) { //add appointment table $appadd = "insert appointment(id_logged, patient_id, date_app, time_app, reason) values(:id_logged, :patient_id, :date_app, :time_app, :reason)"; $appaddstmt = $conn->prepare($appadd); $appaddstmt->bindvalue(":id_logged", $id_logged); $appaddstmt->bindvalue(":patient_id", $lastid); $appaddstmt->bindvalue(":date_app", $date_app); $appaddstmt->bindvalue(":time_app", $time_app); $appaddstmt->bindvalue(":reason", $reason); $appaddstmt->execute(); $arr = array('patient_name'=>$patient_name, 'date_app' =>$date_app); echo json_encode($arr); } else { $msg = "their existing appointment in same time, please specify date , time"; $arr = array('patient_name'=>$msg, 'date_app', $date_app, 'time_app', $time_app); } } } catch(pdoexception $m) { $m->getmessage(); echo "error".$m; } ?>
line 35 $appexiststmt->execute();
: time_app
try remove space
:time_app
Comments
Post a Comment