我将此代码放入我测试的PHP脚本中:
mysql_query("INSERT INTO te_sales(uid,s_credit,s_price,s_date) VALUES ('$user_info[id]','$cPack[t_credit]','$cPack[t_price]',time())");
但是在购买商品时,有关买家的数据不会插入到te_sales
表中的数据库中。这有什么问题?
这是完整的代码:
if(isset($_POST['te_package'])){
// Lets get the data....
$sP = intval($_POST['te_package']);
// Lets check in DB either it is there or not.
$chk = mysql_query("SELECT * FROM te_pack WHERE id='$sP' LIMIT 1");
if(mysql_num_rows($chk)== 1){ // Founded go ahead
// Fetch the sP pack
$cPack = mysql_fetch_array($chk);
// Check user balance...
if($user_info['purchase_balance'] >= $cPack['t_price']){ // Proceed as user
have enough balance to make purchase.
// Lets Cut out the user balance... And give the TE Credits
mysql_query("UPDATE members SET purchase_balance = purchase_balance -
'$cPack[t_price]' , te_credit = te_credit + '$cPack[t_credit]'
WHERE id='$user_info[id]'");
// Insert the logs of sales...
//mysql_query("INSERT INTO te_sales(uid,s_credit,s_price,s_date) VALUES
('$user_info[id]','$cPack[t_credit]','$cPack[t_price]',time())");
$result = mysql_real_escape_string("
INSERT INTO te_sales(uid,s_credit,s_price,s_date)
VALUES ('$user_info[id]','$cPack[t_credit]','$cPack[t_price]',time())
");
if (!$result) {
die('Invalid request : ' . mysql_error());
}
答案 0 :(得分:2)
你看看是否有错误吗?
<?php
$result_data = mysql_query('
INSERT INTO te_sales(uid,s_credit,s_price,s_date)
VALUES (
"'.mysql_real_escape_string($user_info['id']).'",
"'.mysql_real_escape_string($cPack['t_credit']).'",
"'.mysql_real_escape_string($cPack['t_price']).'",
now()
)
');
if (!$result_data) {
die('Invalid query request: ' . mysql_error());
}
?>
答案 1 :(得分:0)
您插入语法错误,请尝试这样
$result_data = mysql_query("
INSERT INTO te_sales(uid,s_credit,s_price,s_date) VALUES ('".$user_info['id']."','".$cPack['t_credit']."','".$cPack['t_price']."',time() )
");
if (!$result_data) {
die('Invalid query request: ' . mysql_error());
}