在检查用户的登录详细信息时,我一直在尝试了解 jQuery 的工作原理。我创建了这些页面:
- db.php(数据库连接)
- signin.html(登录表单)
- check.php(登录检查 - MySQL 选择)
- myscript.js (jQuery)
登录表格:
<script src="js/jquery.min.js"></script>
<script src="js/myscript.js"></script>
<div id="loginForm">
<label>Please Login</label><br/>
<form id="myForm" action="check.php" method="post">
<input name="emailid" id="email" type="text" placeholder="Enter your Email ID"/><br/>
<input name="password" id="pass" type="password" placeholder="Enter your password"/><br/>
<button id="submit"> Login</button>
</form>
</div>
<div id="ack"></div>
myscript.js
$(document).ready(function (){
$("#submit").click(function (){
alert("hi");
if($("#email").val()==""||$("#pass").val()=="")
$("div#ack").html("please enter email and pass");
else
$.post( $("#myForm").attr("action"),
$("#myForm :input").serializeArray(),
function(data){
$("div#ack").html(data);
});
$("#myForm").submit( function(){
return false;
});
});
});
检查.php
$email = $_POST['emailid'];
$pass = $_POST['password'];
include "db.php";
$sql = "select count(*)from students where email = '$email' and password = '$pass';";
$result = mysqli_query($con,$sql);
$row=mysqli_fetch_array($result);
if($row[0]>0)
echo "found result";
else
echo "no result";
一切正常。唯一的问题是数据没有被发布。$_POST[] 正在接收空值,即使我正在输入值。
请帮忙。