我不断收到此错误消息:
致命错误:未捕获的异常' PDOException'消息' SQLSTATE [HY093]:参数号无效:参数未定义'在[CENSORED] /add_test.php:93堆栈跟踪:#0 [CENSORED] /add_test.php(93):PDOStatement->执行()#1 {main}在第93行的[CENSORED] /add_test.php中抛出
代码如下:
$test_name = $_POST['test_name'];
$start_date = $_POST['start_date'];
$start_time = $_POST['start_time'];
$end_date = $_POST['end_date'];
$end_time = $_POST['end_time'];
$teacher_id = $_POST['teacher_id'];
if(isset($_POST['test'])){
$exam_mode = "1";
}
else{
$exam_mode = "0";
}
$subject = $_POST['subject'];
$max_score = $_POST['maxs'];
$qtext = $_POST['qtext'];
$qtitle = $_POST['qtitle'];
$critsel = $_POST['criteria_selector'];
$crita = $_POST['criteria'];
$edit = $_POST['editable_response'];
$pinnumber = mt_rand(1000000,9999999);
$start_datetime = $start_date;
$start_datetime .= ":";
$start_datetime .= $start_time;
$true_start_time = date_create_from_format("d.m.Y:H.i",$start_datetime);
$db_start_time = $true_start_time->format("Y-m-d H:i:s");
$end_datetime = $end_date;
$end_datetime .= ":";
$end_datetime .= $end_time;
$true_end_time = date_create_from_format("d.m.Y:H.i",$end_datetime);
$db_end_time = $true_end_time->format("Y-m-d H:i:s");
include ('config.php');
try {
$cnnxn = new PDO("mysql:host=$db_host;dbname=$db_name", $db_username, $db_password);
} catch (PDOException $e) {
die("ERROR: " . $e->getMessage());
}
$cnnxn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$cnnxn->exec("SET NAMES utf8");
$query = $cnnxn->prepare("INSERT INTO assignments (teacher, start, end, exam, question_text, criteria, criteria_visibility, question_title, subject, pin, editable, max_score) VALUES (:teacher, :start, :end, :exam, :question_text, :criteria, :criteria_visibility, :question_title, :subject, :pin, :editable, :max_score)");
$query->bindParam(':teacher', $userid);
$query->bindParam(':start', $db_start_time);
$query->bindParam(':end', $db_end_time);
$query->bindParam(':exam', $exam_mode);
$query->bindParam('::question_text', $qtext);
$query->bindParam(':criteria', $crita);
$query->bindParam(':criteria_visibility', $critsel);
$query->bindParam(':question_title', $qtitle);
$query->bindParam(':subject', $subject);
$query->bindParam(':pin', $pinnumber);
$query->bindParam(':editable', $edit);
$query->bindParam(':max_score', $max_score);
$query->execute();
if ($query !== false)
{
print "<div class=\"message\">Success!</div>";
}
$cnnxn = null;
}
(我知道日期部分是丑陋的。我的头直接工作已经太晚了。因为PDOException错误,我的头撞到了墙上。)
第93行是脚本执行查询的地方。
有什么想法吗?
答案 0 :(得分:1)
仅供参考,这是一个错字
$query->bindParam('::question_text', $qtext);
应该是
$query->bindParam(':question_text', $qtext);