I am trying to create a table in MySQL dynamically from PHP.
User inputs should be inserted into that table using jQuery,AJAX and PHP.
my code is looking like this.
var toServer = brandname+','+prodname+','+qty;
$.ajax({
type: 'POST',
url: 'sample.php',
data: toServer,
cache: false,
success: function(res){
alert(res);
},
error: function(){
alert(1);
}
})
In sample.php:
require '../models/orderClass.php';
$order = new orderClass;
$data = explode(',',$_REQUEST['toServer']);
$res = $order->addToCart('[email protected]', $data[0], $data[1],$data[2]);
echo $res;
In orderClass:
$this->con = new mysqli('servername','user','pass','dbnaem');
if($this->con->connect_error)
{
echo($this->con->connect_error);
}
Without AJAX, its working. After adding $.ajax() its not working. Please help me out Thanks in advance
I am new to AJAX and I added error: function at last since it was not working.