我在控制台中获得了正确的日志,但它没有进入数据库,不过我看不出我的 PHP 有什么问题。谁能看到可能是什么问题?
jQuery代码:
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Create an account": function() {
var fname = $( "#guestfname" ).val();
var lname = $( "#guestlname" ).val();
var gender = $( "#guestgender" ).val();
var address = $( "#guestaddress" ).val();
var city = $( "#guestcity" ).val();
var state = $( "#gueststate" ).val();
var zip = $( "#guestzip" ).val();
var phone = $( "#guestphone" ).val();
var email = $( "#guestemail" ).val();
var dob = $( "#guestdob" ).val();
var dataString ={fname:fname, lname:lname, gender:gender, address:address,
city:city, state:state, zip:zip, phone:phone, email:email,
dob:dob};
console.log(dataString);
$.ajax({
type: "POST",
url: "classes/add_guest.php",
data: dataString,
cache: false,
success: function(html)
{
$('.guestinfo').html(html);
}
});
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
}
});
$( "#create-user" )
.button()
.click(function() {
$( "#dialog-form" ).dialog( "open" );
});
});
PHP mySQL查询代码:
<?php
//open connection
require_once('../config/db.php');
$con = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
//get date
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$gender = $_POST['gender'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$dob = $_POST['dob'];
mysqli_query($con, 'INSERT INTO guests(fname, lname, gender, address, city, state, zip, phone, email, dob)
VALUES("'.$fname.'","'.$lname.'","'.$gender.'","'.$address.'","'.$city.'","'.$state.'",'.
$zip.','.$phone.',"'.$email.'",'.$dob.'');
mysqli_close($con);
?>