我試圖在數據庫中插入$ _COOKIE ['PHPSESSID']與pdo,但我有問題,有人可以幫忙嗎?如何使用PDO將PHPSESSID插入數據庫?
這裏是db表設計:db表名:unregistered_customer_orders
session_id (int)
sel_article_id (varchar, 32)
sel_article_qty(smallint)
sel_article_color(varchar)
sel_article_size(varchar)
order_date(datetime)
這裏是代碼
session_start();
try {
include_once'../includes/connect.inc.php';
$q ="INSERT INTO unregistered_customer_orders SET
session_id = $_COOKIE['PHPSESSID'] ,
sel_article_id = :sel_article_id,
sel_article_qty =:sel_article_qty,
sel_article_color = :sel_article_color,
sel_article_size = :sel_article_size,
order_date = NOW()";
$stm = $pdo->prepare($q);
$stm->bindValue(':sel_article_id', $sel_article_id);
$stm->bindValue(':sel_article_qty', $sel_article_qty);
$stm->bindValue(':sel_article_color', $sel_article_color);
$stm->bindValue(':sel_article_size', $sel_article_size);
$stm->execute();
if ($stm) {
echo "Insert";
exit();
}
else{
echo "Insert failed";
exit();
}
} catch (PDOException $e) {
echo "sth got wrong with the insert".$e->getMessage();
}
http://php.net/manual/en/pdo.error-handling.php --- http://php.net/manual/en/function.error-reporting.php –
您正在使用準備好的語句不正確。這個'$ _COOKIE ['PHPSESSID']'也應該綁定。 – chris85