你有一些不匹配的变量.
$poster_id – $poster_name – $message
在你的绑定中与之对齐:
$user_id,$user,$comment
这应该现在有效:
$pid = '1';
$pname = 'name';
$poster_id = '2';
$poster_name = 'name2';
$message = 'This is the message';
$datetime = date("M d, Y");
// insert into database
$ins = "INSERT INTO messages (profile_id, profile_name, poster_id, poster_name, message, countnum, postdate) VALUES (?, ?, ?, ?, ?, ?, ?)";
$stmt = $con->prepare($ins);
$num = 1;
$stmt->bind_param('isissis', $pid, $pname, $poster_id, $poster_name, $message, $num, $datetime);
$stmt->execute();
?>
但是,你应该替换$stmt-> execute(); with if(!$stmt-> execute()){trigger_error(“有一个错误……”.$con>错误,E_USER_WARNING);}
为了抓住错误.
还要在文件顶部添加error reporting,这有助于查找错误.
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
这将发出一个未定义的变量警告信号.
旁注:错误报告应该只在暂存中完成,而不是生产.
洞察力
正如Ghost所指出的那样:
$datetime格式M d,Y也是可疑的,它可能搞砸Y-m-d H:i:s的格式为DATETIME列,如果确实如此.
因此你可能需要改变
$datetime = date("M d, Y");
至
$datetime = date("Y-m-d H:i:s");
要么
$datetime = date("Y-m-d");
取决于列类型的设置.