I have this jquery script
$(function() { // <----doc ready starts
$("#btn1").click(function(e) {
e.preventDefault();
var name = $("#id1").val();
var last_name = $("#id2").val();
var dataString = {'name=':name, 'last_name': last_name};
$.ajax({
type: 'POST',
dataType: 'jsonp',
url: 'http://localhost/insert.php',
success: function(data) {
alert(data);
}
});
});
});
And this php one inserting parameters from the first script into mysql database:
<?php
$conn = mysqli_connect('localhost', 'root', '');
$name = $_POST['name'];
$last_name = $_POST['last_name'];
$mysqli = new mysqli('localhost','root','','os');
if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
$insert_row = $mysqli->query("INSERT INTO table_info (name, name2) VALUES($name, $last_name)");
if ($insert_row){
print 'Success! ID of last inserted record is : ' .$mysqli->insert_id .'<br />';
}
else {
die('Error : ('. $mysqli->errno .') '. $mysqli->error);
}
$mysqli->free();
$mysqli->close();
?>
When I'm trying to run it, it is failing with that error:
Notice: Undefined index: name in C:\wamp\www\insert.php on line 3
Notice: Undefined index: last_name in C:\wamp\www\insert.php on line 4
Error : (1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' )' at line 1
What's wrong here, sorry for stupid question, this is my first experience with php and jQuery both.