0

I am new to jquery-ajax. My payment_gateway_1.php is:

<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>

And paymentgatewayverify.php is :

<?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);
?>

I was expecting the datas will be inserted to my mysql table, but they are not ! Whats wrong with my code ?

Nitish
  • 2,695
  • 9
  • 53
  • 88
  • Are there any errors? If you `var_dump()` `$name`, `$bill`, `$phone` are you getting values? – Mattiavelli Jul 29 '13 at 17:44
  • I tried with `var_dump($_POST)`, but its same. a blank page – Nitish Jul 29 '13 at 17:46
  • 1
    [Check out this post](http://stackoverflow.com/questions/5004233/jquery-ajax-post-example) and compare the format of your Ajax request vs theirs. If you're getting a blank page, that means that your `ajax` probably isn't working. For example, you put `'url'` instead of `url`. Also, [this page](http://api.jquery.com/jQuery.ajax/) has more examples. – Mattiavelli Jul 29 '13 at 17:52
  • Using PDO, $_POST, And where is the codeigniter? – Hashem Qolami Jul 29 '13 at 18:08
  • `payment_gateway_1.php` is the view here. And I did not get you – Nitish Jul 29 '13 at 18:10
  • doesn't appear that `success` or `dataType` are defined... use browser console to look for any script errors thrown and to inspect ajax request – charlietfl Jul 30 '13 at 01:53
  • what response are you getting from your ajax requests? check the network tab in chrome developer tools or firebug if your using Firefox. – Jeemusu Jul 30 '13 at 02:20

0 Answers0