我正在浏览this post since 2 days中显示的错误。
以下是来自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)
这是我得到的错误:
带有消息'SQLSTATE [HY093]的异常'PDOException':无效 参数号:绑定变量数与数量不匹配 C:\ wamp \ www \ dentist \ pages \ add_appoint.php中的标记:35堆栈跟踪:
0 C:\ wamp \ www \ dentist \ pages \ add_appoint.php(35):PDOStatement-> execute()#1 {main}
这是PHP代码:
<?php
//Set error reporting on
error_reporting(E_ALL);
ini_set("display_errors", 1);
//Include connection file
require_once('../include/global.php');
//Json and PHP header
header('Content-Type: application/json');
$user = $_SESSION['username'];
$id_logged = $_SESSION['login_id'];
try
{
$arr = array();
//Values From 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 and time exist
$appExist = "SELECT * FROM appointment WHERE id_logged = :id_logged AND date_app = :date_app and 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 to appointment table
$appAdd = "INSERT INTO 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 INTO 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 and time exist
$appExist = "SELECT * FROM appointment WHERE id_logged = :id_logged AND date_app = :date_app and 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 to appointment table
$appAdd = "INSERT INTO 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 is another existing appointment in the same time, please specify another date and time";
$arr = array('patient_name'=>$msg, 'date_app', $date_app, 'time_app', $time_app);
}
}
}
catch(PDOException $m)
{
$m->getMessage();
echo "error".$m;
}
?>
第35行是$appExistStmt->execute();
答案 0 :(得分:1)
: time_app
尝试删除空格
:time_app