PHP:PDO插入查詢失敗
if(strcasecmp($refId, 'guest') == 0)
{
if(strcasecmp($amount, '24.95') == 0)
{
$credits = 20;
$plan = 'cool';
}
if(strcasecmp($amount, '45.95') == 0)
{
$credits = 40;
$plan = 'awesome';
}
if(strcasecmp($amount, '69.95') == 0)
{
$credits = 60;
$plan = 'Supreme';
}
$keyy = generate_key_string();
$query = $pdo->prepare("INSERT INTO keys (keys_key, keys_plan, keys_credit) VALUES (?, ?, ?)");
$query->bindValue(1, $keyy);
$query->bindValue(2, $plan);
$query->bindValue(3, $credits);
if(!$query->execute())
{
echo 'failed' . '<br/>';
echo $plan . '<br/>';
echo $keyy . '<br/>';
echo $credits;
}
}
SQL表:
CREATE TABLE `keys` (
`keys_key` varchar(29) NOT NULL,
`keys_credits` int(11) NOT NULL,
`keys_plan` varchar(255) NOT NULL,
PRIMARY KEY (`keys_key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
我知道的值是有,因爲這是我的輸出
failed
cool
CDGSI-DUEXP-M9BUZ-4VMQA-YSLIU
20
查詢似乎沒有正在爲這個插入工作,我在其他頁面上有不同的插入功能,他們工作正常。由於
嘗試添加'的var_dump($查詢 - > ERRORINFO())'來查看查詢產生的錯誤。 – andrewsi
'array(3){[0] => string(5)「42000」[1] => int(1064)[2] => string(226)「您的SQL語法錯誤; (key_key,keys_plan,keys_credit)VALUES('B1VN9-GVPQ1-RT9X3-0BHBU-I2PIU','at line 1「}'如果keys_key的varchar爲'只是文字? – ZZPLKF
請參閱echo_me的回答:) – andrewsi