我是新手jquery-ajax
。我payment_gateway_1.php
的是:
<script>
var cst_dta = {
'name' : 'amar',
'total_bill' : '550',
'phone' : '3612303957'
};
$(document).ready(function(){
//alert(cst_dta['name']); alerts amar
$.ajax({
'url': 'http://localhost/nitish/paymentgatewayverify.php',
'type': 'POST',
'data': cst_dta,
'cache' : false,
success: success,
dataType: dataType
});
});
</script>
并且 paymentgatewayverify.php
是:
<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'democart';
$name = $_POST['name'];
$bill = $_POST['total_bill'];
$phone = $_POST['phone'];
try
{
$conn = new PDO('mysql:host=$host;dbname=$db',$username,$password);
}catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
$stmt = $conn->prepare("INSERT INTO data_table(name,bill,phone) VALUES(:name,:bill,:phone)");
$stmt->bindParam(":name",$name);
$stmt->bindParam(":bill",$bill);
$stmt->bindParam(":phone",$phone);
$stmt->execute();
$trans_id = 123444;
$trans_status = 1;
header('Location:http://localhost/cishop/index.php/checkout/payment_status/?status='.$trans_status.'&trans_id='.$trans_id);
?>
我原以为数据会被插入到我的 mysql 表中,但事实并非如此!我的代码有什么问题?