我不知道为什么我无法在 JSON 中收到成功消息。数据已很好地插入数据库,因此可以正常工作,但没有回调消息(成功)。我不知道为什么。
这个文件是在数据库中插入数据的地方。
include ("connect_to_mysql.php");
if ( isset($_POST['register'])) {
$First_Name = mysql_real_escape_string($_POST['firstname']);
$Last_Name = mysql_real_escape_string($_POST['lastname']);
$Email = mysql_real_escape_string($_POST['email']);
$Password = mysql_real_escape_string($_POST['password']);
$Gender = mysql_real_escape_string($_POST['gender']);
$sql3 =mysql_query("SELECT email FROM members WHERE email = '$Email' ");
$result3= mysql_num_rows($sql3) ;
$found ='';
if ($result3 == 1 ) {
$found = "email already exist ! ";
} else {
mysql_query("INSERT INTO members (firstname, lastname,gender, email, password,bio_body, sign_up_date , account_type)
VALUES( '".$First_Name."', '".$Last_Name."','".$Gender."','".$Email."','".$Password."','NULL' ,NOW() , 'a' ) ");
$found = "registered succefully !";
}
echo json_encode(array('returned_val' => "$found"));
//-- i have tried this also echo json_encode(array('returned_val' => $found));
}
这是我的ajax
$(document).ready(function(){
$('#register').click(function() {
$('#mydata').html('Saving your data...<img src="images/loading.gif" />');
$.ajax({
url: "sendata.php",
dataType: 'json' ,
data: {
firstname: firstname.value,
lastname: lastname.value,
email: email.value,
password: password.value,
gender: gender.value
},
type: 'POST',
success: function(data){
$('#mydata').html("<span style='font-size:18px; color: green;'> Your data is saved succefully! </span>").delay(3000).fadeOut('fast');
alert(data.returned_val);
alert (1);
}
});
});
});
OBS:关于mysql或一些安全的东西(密码)我知道,当我解决这个问题时我会修复它们。
谢谢你的时间。
编辑:我没有错误信息
编辑。html表单
<form action="" method="post" enctype="multipart/form-data">
<table width="100%" class="noborder" >
<tr>
<td width="23%" height="47" class="right">First Name:</td>
<td width="77%" class="left left_nowrap">
<input type="text" class="left left_nowrap tb10 border1" name ="firstname" id="First_Name" value="<?php echo $_SESSION['firstname']; ?>" />
</td>
</tr>
<tr>
<td height="47" class="right">Last Name:</td>
<td valign="middle" class="left left_nowrap">
<input type="text" class="left left_nowrap tb10 border1" name ="lastname" id="Last_Name" value="<?php echo $_SESSION['lastname']; ?>" /><br/>
</td>
</tr>
<tr>
........
<td valign="middle" class="left"><input id="register" name="register" type="button" class="submit1 tb10 border4" value="Sign - Up" /></td>