如何使用javascript和php检查签名,像这样?
首先,用户会将数据填入输入username
和password
如果username
和password
更正,那么它会提醒SUCCESS
但是username
或password
不正确,它会提醒FAIL
我测试了我的代码,但没有工作。我怎么能这样做?
HTML
<form method="post" action="" ENCTYPE = "multipart/form-data" onsubmit="return checkform(this);" id="sign_in_fid">
<label>
Your Username
</label>
<input type="text" name="username" id="username">
<br>
<label>
Your Password
</label>
<input type="password" name="password" id="password">
<br>
<br>
<input name="submit" type="submit" value="Sign in"/>
</form>
JAVASCRIPT
<script language="JavaScript" type="text/javascript">
function checkform ( form )
{
var username_val = document.getElementById("username").value;
var password_val = document.getElementById("password").value;
</script>
<?PHP
include("connect.php");
$strUsername = "<script>document.writeln(username_val);</script>";
$strPassword = "<script>document.writeln(password_val);</script>";
$sql = "SELECT * FROM av8_users WHERE BINARY username = '$strUsername' and password = '$strPassword'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$active=$row['active'];
$count=mysql_num_rows($result);
if($count==1)
{
?>
<script>
alert("SUCCESS");
</script>
<?PHP
}
else
{
?>
<script>
alert("FAIL");
</script>
<?PHP
}
?>
<script>
return true ;
}
</script>
答案 0 :(得分:-1)
您的代码失败的原因是您在PHP代码中使用JavaScript。 尝试更改
$strUsername = "<script>document.writeln(username_val);</script>";
$strPassword = "<script>document.writeln(password_val);</script>";
到
$strUsername = $_POST['username'];
$strPassword = $_POST['password'];