我还是JQuery和Php的新手。 我正在尝试创建一个连接到signup.php文件的简单注册表单
这是JQuery:
<!-- jQuery Here -->
<script>
$(document).ready(function(){
$("#signup").click(function(){
var fullname=$("#fullname").val();
var email=$("#email").val();
var password=$("#password").val();
var dataString="fullname="+fullname+"&email="+email+"&password="+password+"&signup=";
if($.trim(fullname).length>0 & $.trim(email).length>0 & $.trim(password).length>0) {
$.ajax({
type: "POST",
url: "http://localhost/signup.php",
data: dataString,
success: function(html){
if(html=="success") { // display if success
alert("Thank you for Registering with us! you can login now");
}
else if(html=="exist") { // display if exist
alert("Hey! You alreay has account! you can login with us");
}
else if(html=="failed") {//display if failed
alert("Something Went wrong");
}
alert(html);
}
});
}
return false;
});
});
</script>
<!-- end here -->
这是php:
<?php
$connection = @mysql_connect("localhost", "root", ""); // Establishing connection with server
$db = mysql_select_db("try", $connection); // Selecting Database
if(isset($_POST['signup'])) {
$fullname=mysql_real_escape_string(htmlspecialchars(trim($_POST['fullname'])));
$email=mysql_real_escape_string(htmlspecialchars(trim($_POST['email'])));
$password=mysql_real_escape_string(htmlspecialchars(trim($_POST['password'])));
$login=mysql_num_rows(mysql_query("select * from `phonegap_login` where `email`='$email'"));
if($login!=0) {
echo "exist"; // return if exist
}
else {
$date=date("d-m-y h:i:s");
$q=mysql_query("insert into `phonegap_login` (`reg_date`,`fullname`,`email`,`password`) values ('$date','$fullname','$email','$password')");
if($q) {
echo "success"; // return if success
}
else {
echo "failed"; // return if failed
}
}
echo mysql_error();
}
mysql_close ($connection); // close connection
?>
现在的问题是我确实将数据添加到数据库中,但是我无法将echo返回到我的JQuery,因此它不会显示结果。
任何答案都将不胜感激。