将事务id和详细信息插入mysql

时间:2015-09-23 15:27:44

标签: php mysql authorize.net



<?php
if ( isset($_POST['btnSubmit']) ) {

// gather card info
// gather card info
$transaction->amount ='9.99';

$transaction->card_num =$_POST['card_num'];
$transaction->exp_date =$_POST['exp_date'];

// gather card info
// gather card info

//capture info

$response = $transaction->authorizeAndCapture();

//capture info

//check if approved
//check if approved

if($response->approved){
  echo "<h1>Success! The test credit card has been charged!</h1>";
  echo "Transaction ID: ". $response->transaction_id;

//check if approved
//check if approved

// if approved insert into sql data base
// if approved insert into sql data base

$query = "INSERT INTO payments (card_num,exp_date) VALUES ('$card_num','$exp_dat')";
        $result = mysql_query($query);

// if approved insert into sql data base
// if approved insert into sql data base

}else{
  echo $response->error_message;
}
}
?>
&#13;
&#13;
&#13;

我正在尝试运行付款集成代码,当付款获得批准后,我无法将付款详细信息插入MySQL表格。它说:

  

未定义的变量:exp_dat&#34; &#34;未定义的变量:card_num。

我不确定如何定义它,因为我无法将$放在card_num之前$transaction->card_num =$_POST['card_num'];

我也无法在那里插入交易ID。

谢谢

2 个答案:

答案 0 :(得分:1)

您没有变量$exp_dat,正如错误所说,您的变量是$transaction->exp_date_POST['exp_date']

话虽如此,请阅读此链接 How can I prevent SQL injection in PHP?并在绑定变量时将其转换为mysli_查询,或使用PDO。

答案 1 :(得分:0)

错误信息非常清楚。

$exp_dat不存在(但$transaction->exp_date确实存在)

$card_num不存在(但$transaction->card_num确实存在)

在查询中使用这些变量:

$query = "INSERT INTO payments (card_num,exp_date) 
          VALUES ('$transaction->card_num','$transaction->exp_date')";