I'm having difficulties send data to MySQL via PHP and a Jquery ajax call, I'm new to this so apologies if its something obvious - any help would be appreciated.
connect database php
<?php
DEFINE ('DB_USER', 'user account');
DEFINE ('DB_PSWD', 'password');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'dbname');
$dbcon = mysqli_connect(DB_HOST, DB_USER, DB_PSWD, DB_NAME);
?>
call.php:
<?php
include(connect_db.php);
$name = $_POST['name'];
$age = $_POST['age'];
mysql_query("INSERT INTO user ('name', 'age') VALUES ('$name','$age')");
?>
ajax call:
The name and age are added via function
function send (name, age) {
$.ajax({
type: "POST",
url : "scripts/call.php",
data : "name=" + name + "&age=" + age,
success: function(data) {
console.log('success');
},
error: function () {
console.log('failed');
}
});
}
I do get a success console.lo however no data is every shown in the database.
Thanks, Stephen