當我插入到mysql時,我反覆得到語法錯誤,通常這工作正常,但我似乎無法得到它的工作。我可以回顯變量沒有問題,但由於某種原因,我不能插入它們。INSERT INTO語法錯誤,但通常應該可以工作
變量(會話瓦爾是從另一個頁面帶過來的)
session_start();
$name=$_SESSION['bName'];
$email=$_SESSION['email'];
$ship_address = $_SESSION['sAddress'];
$voucher=$_SESSION['voucher'];
$sku=$_SESSION['sku'];
$credit_card=$_POST['credit_card'];
$security_code=$_POST['security_code'];
$payment_type=$_POST['payment_type'];
$cc_number=substr($credit_card, 0, 4) . str_repeat('x', (strlen($credit_card) - 4)) . substr($credit_card, -4, 4);
$phone=$_SESSION['billPhone'];
$status="Redeemed";
$date = date('Y/m/d');
$tracking ="";
插入查詢
//Insert Queries
$sqlInsert = "INSERT INTO `customers`(`name`, `email`, `address`, `phone`, `sku`, `creditcard`, `securitycode`, `paymenttype`, `voucher`, `purchase_id`, `tracking`, `status`, `date_recieved`)
VALUES($name, $email, $ship_address, $phone, $sku, $credit_card, $security_code, $payment_type, $voucher, $purchase_id, $tracking, $status, $date)";
mysql_query($sqlInsert) or die ('Error Inserting into database' . mysql_error());
我也試過
VALUES('$name', '$email', '$ship_address', '$phone', '$sku', '$credit_card', '$security_code', '$payment_type', '$voucher', '$purchase_id', '$tracking', '$status', '$date')
,但它不工作。我得到的錯誤是
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'lastname, [email protected], 22 toronto ont l6a0l4, 416-123-4567, 10, 1234567' at line 1
任何想法?
謝謝
執行'echo $ sqlInsert'併發布輸出。你必須將字符串值放入引號中,後一種方法應該可以工作,但是**必須轉義和清除值! – JJJ