我正在努力使用 PDO 进行 INSERT 查询。
完全相同的代码使用 msql_query 函数工作,但我在尝试转换为 PDO 时遇到了困难。
谁能告诉我为什么这段代码没有在表中插入任何东西?
$weaponinvite = $_POST['weaponbtn'];
if ($weaponinvite){
$weaponinviteperson = $_POST['weaponinvitename'];
if(!$weaponinviteperson){
echo "You must enter a playername";
}else{
$invitequery = "SELECT count(*) FROM `users` WHERE username=:ocinvited";
$checkinvite = $db->prepare($invitequery);
$checkinvite->execute(array(':ocinvited'=>$weaponinviteperson));
$checkrows = $checkinvite->fetchColumn();
if ($checkrows == 0){
echo "No such user. Please check and try again";
}else{
$ocpositioninv = "Weapon Master";
$message = "Congratulations, You have been invited to join an organised crime in $oclocation as a $ocpositioninv . Click here to accept";
$ocinvitestatement ="INSERT INTO `inbox`(`id`,`to`,`from`,`message`,`date`,`read`,`saved`,`event_id`,`subject`) VALUES ('', ':ocinvited', ':ocinviter', ':message', ':date', '0', '0', '0', 'Organised Crime Invitation - :ocpositioninvsub')";
$wpinvstate = $db->prepare($ocinvitestatement);
$wpinvstate->execute(array(':ocinvited'=>$weaponinviteperson,
':ocinviter'=>$username,
':message'=>$message,
':date'=>$date,
':ocpositioninvsub'=>$ocpositioninv));
echo" invitation sent";
}
}
}
一切正常,在正确的阶段给出所有正确的回声,即使在最后一个 ELSE,它也会回显:邀请已发送,但它只是不会将数据插入表中:(
我浏览了这里/互联网上的一些帖子,看来我的代码是它的本意?
有人可以帮忙吗?