此查询运行时没有错误,但它没有向数据库添加任何内容我无法弄明白我到处都看。你们有什么感想?我的数据库连接在另一个文件中定义,它可以工作,因为其他查询仍然有效。
function processs_form(){
$clean_fullname = sanitize($_POST['fullname']);
$clean_sport = sanitize($_POST['sport']);
$clean_package = sanitize($_POST['package']);
$clean_weight = sanitize($_POST['weight']);
$clean_height = sanitize($_POST['height']);
$clean_gpa = sanitize($_POST['GPA']);
$clean_number = sanitize($_POST['number']);
$clean_school = sanitize($_POST['school']);
$clean_gradYear = sanitize($_POST['gradYear']);
$clean_yearRecorded = sanitize($_POST['yearRecorded']);
$clean_postion = sanitize($_POST['position']);
$clean_info = sanitize($_POST['additioninfo']);
$reply_value = 1;
GLOBAL $mysqli;
$stmt = $mysqli->prepare("INSERT INTO video_tickets (`ticket_id`, `user_name`, `new_reply`, `full_name`, `sport`,
`position`, `year_recorded`, `grad_year`, `school`, `player_number`, `gpa`, `height`, `weight`,
`package`, `addition_info`) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param('isisssiisidddss', $loggedInUser->user_id, $loggedInUser->username, $reply_value,
$clean_fullname, $clean_sport , $clean_postion,
$clean_yearRecorded, $grad_year, $clean_school, $clean_number, $clean_gpa,
$clean_height, $clean_weight, $clean_package, $clean_info);
$stmt->execute();
$stmt->close();
$message = <<<_HTML_
Your Ticket Has Been submited You'll get a Reply within 24 Hours.
_HTML_;
print nl2br(htmlentities($message));
}
答案 0 :(得分:1)
您的绑定已$grad_year
但您使用$clean_gradYear
作为变量:
$clean_gradYear = sanitize($_POST['gradYear']);
将bind_param值中的$grad_year
更改为$clean_gradYear
。
如果一个失败,您的整个查询都将失败。
错误报告会发出错误信号:
答案 1 :(得分:0)
这是一个很好的例子,说明为什么检查prepare
,execute
,bind_param
等的返回值很重要。
您的查询很可能实际上失败了。它可能在bind_param
阶段,正如其他人所指出的那样 - 你绑定的一个参数是未初始化的。
例如,execute()
向呼叫者返回bool
,表示成功或失败。您可以按如下方式检查:
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
有关更完整的指南:PHP Prepared Statements。