I cannot figure out why the data is not getting inserted to my mysql database when it is being logged to the console properly.
My form as follows:
<form id="insertForm" type="post">
name: <input type="text" id="name" name="name">
activity: <input type="text" id="activity" name="activity">
level: <input type="number" id="level" name="level">
<input type="button" name="add" id="add" value="add">
</form>
My ajax call:
<script type="text/javascript">
$(document).ready(function() {
$("#add").click(function(e){
var Data = $("#insertForm").serializeArray();
console.log(Data);
$.ajax({
url : "insert.php",
type: "POST",
data : Data,
success:function(data, textStatus, jqXHR)
{
$('#msg').html(data);
}
});
$("#msg").slideDown("slow");
e.preventDefault();
});
});
</script>
My PHP insert:
<?php
if (!empty($_POST))
{
$dbhost = 'localhost';
$dbuser = 'lot_root';
$dbpass = '';
$con = mysql_connect($dbhost, $dbuser, $dbpass);
$name = mysql_real_escape_string($_POST['name']);
$activity = mysql_real_escape_string($_POST['activity']);
$level = $_POST['level'];
$sql = "INSERT INTO lottt ".
"(name, activity, level) ".
"VALUES('$name','$activity', '$level')";
mysql_select_db('lot');
mysql_close($con);
}
?>
When i insert the data via the input fields it gets logged to the js console fine like so [Object, Object, Object]0: Objectname: "character_name"value: "aSD"__proto__: Object1: Object2: Objectlength: 3__proto__: Array[0]
but nothing is inserted into the mysql database after a quick check.