我已经厌倦了找出为什么这个login.php可以在localhost环境中正常运行但不能在实时服务器中正常运行的麻烦。登录时,输入错误的用户名和密码出错,但在本地主机上则成功。与db的连接正确。
任何人都可以帮助我检查我的编码。
下面是我的代码
<?php require_once('Connections/conn.php'); ?>
<?php
session_start();
if(isset($_POST["s_username"]) && isset($_POST["s_password"])){
$s_username = $_POST["s_username"];
$s_password = $_POST["s_password"];
echo "<script>window.alert('$s_username - $s_password');</script>";
$sql= mysql_query("SELECT * FROM student WHERE studentNo = $s_username AND studentPswd = $s_password LIMIT 1");
$sql2= mysql_query("SELECT * FROM clockin WHERE studentNo = '$s_username' AND status=0 LIMIT 1");
$existCount = mysql_num_rows($sql);
$s_status = "1";
if($existCount==1){
while($row = mysql_fetch_array($sql)){
$s_no=$row['studentNo'];
$s_name=$row['studentName'];
}
if($existCount2==1){
while($row2 = mysql_fetch_array($sql2)){
$s_status=$row2['status'];
$s_clockid=$row2['clockID'];
}}
$_SESSION["s_no"]=$s_no;
$_SESSION["MM_Username"]=$s_username;
if($sql==true){
echo "<script>window.alert('Login Success');</script>";
</script>";
if($s_status==1){
header("refresh:1 ,url=beginSession.php ");
exit();
}
else {
echo "<script>window.alert('Sesi Lepas Belum Ditamatkan.');</script>";
header("refresh:1 ,url=startedSession2.php?clockid=$s_clockid");
exit();
}
}
}
else{
echo "<script>window.alert('Login Failed.');</script>";
header("refresh:1 ,url=login.php");
exit();
}
}
?>
<body>
<div class="wrapper-page">
<div class="panel panel-color panel-primary panel-pages">
<div class="panel-heading bg-img">
<div class="bg-overlay"></div>
<h3 class="text-center m-t-10 text-white"><strong>Masuk ke</strong>
<p><a href="#"><img src="img/logo2.png" alt="" title=""></a></p></h3>
</div>
<div class="panel-body">
<form class="form-horizontal m-t-20" id="form1" method="post" action="login.php">
<div class="form-group">
<div class="col-xs-12">
<input name="s_username" class="form-control input-lg" type="text" required="" placeholder="Username">
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<input name="s_password" class="form-control input-lg" type="password" required="" placeholder="Password">
</div>
</div>
<div class="form-group text-center m-t-40">
<div class="col-xs-12"><label>
<button class="btn btn-primary btn-lg w-lg waves-effect waves-light" type="submit" value="Log in">Log In</button></label>
<label><a href="reg2.php" class="btn btn-primary btn-lg w-lg waves-effect waves-light">Daftar Baru</a></label>
</div>
</div>
</form>
</div>
</div>
</div>
</body>
我希望任何人都能帮助我。
谢谢
答案 0 :(得分:1)
尝试一下
session_start();
require_once('Connections/conn.php');
session_start();
始终位于页面顶部。
还删除其他结束语:
echo "<script>window.alert('Login Success');</script>";
答案 1 :(得分:1)
此代码导致语法错误:
echo "<script>window.alert('Login Success');</script>";
</script>";
删除其他</script>"
:
echo "<script>window.alert('Login Success');</script>";
https://www.tinywebhut.com/errors-and-custom-error-handling-in-php-56
小心
您正在使用不推荐使用的mysql
,请改用mysqli
扩展名。我想您知道SQL注入。始终使用准备好的语句。
准备好的语句已经有助于消除大量问题,以使查询正常运行。