请帮助我..我正在尝试使用phonegap和jquery mobile,jquery将表单提交到数据库mysql,与服务器端的连接完成并且成功的消息是触发但重新加载我的数据库我无法获取数据插入数据库表。
function onDeviceReady(){
alert('device is up');
$("#subButton").click(function() {
var firstname = $("#firstname").val();
var lastname = $("#lastname").val();
var date = $("#date").val();
var email = $("#email").val();
var sendData = { "firstname": firstname, "lastname": lastname, "date": date, "email": email, };
$.ajax({
type: "POST",
url: "http:/domain.com/save.php",
data: sendData,
success: function(data) {
$("#info").html(data);
}
});
alert("Hello ");
alert($("#firstname").val());
alert($("#lastname").val());
alert($("#date").val());
alert($("#email").val());
return false;
});
}
</script>
我的PHP代码
$dsn = "mysql:host=$host; dbname=$dbname";
$pdo = new PDO($dsn, $user, $pass);
$firstname = $_POST["firstname"]; $lastname = $_POST["lastname"]; $date = $_POST["date"]; $email = $_POST["email"];
mysqli_query($con, "INSERT INTO data (firstname,lastname,date,email) VALUES ('$firstname' , '$lastname' , '$date' , '$email')");
$pdo->exec($sql); echo "Your comment has been sent"; } catch (PDOException $e) { die('Opps' .$e->getMessage()); } ?>