您好,我正在处理登录页面,我遇到的问题是,当我输入用户名并登录时,页面更改为回显错误的用户名或密码。
它似乎没有进入 login_success.php,这导致认为问题出在 sql 语法上,但我还没有找到原因的答案。我还认为可能是 if($count==1){ 并尝试 ($count>1){ 没有成功。
我已经在网上搜索并尝试了几种不同的方法,但没有任何效果。我是新手,将研究停止 sqlinjection 的方法,但是该站点尚未上线,仅用于练习:) 这个社区对我的学习有很大帮助,提前谢谢大家
HTML 登录页面.html
<form id=login name="login" action="login.php" method="post">
<fieldset id=fs>
<legend>Vault Security Console:</legend>
<!-- legeng tage creates a header title for the fieldset box, filedset pulls all data in the tag to gether with a box around it. -->
UserName: <input type="text" name="username"> <br>
Password: <input type="password" name="password"> <br>
<input type="submit" value="Login"> <input type="submit" value="Register">
</fieldset>
</form>
php-Login.php
<?php
// Create connection
$con=mysqli_connect('172.16.254.111',"user","password","Faults"); //(connection location , username to sql, password to sql, name of db)
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//below is the variables from the login form
$username = $_POST['username'];
$password = md5(strip_tags($_POST['password']));
$sql="SELECT * FROM Users WHERE username='.addslashes($username).' and password='.addslashes($password).'";
$result=mysqli_query($sql);
//Mysql_num_row is counting table row
$count=mysqli_num_rows($result);
if($count==1){
session_register("username");
session_register("password");
header('location:login_success.php');
}
//if false echo below
else {
echo "<H2>Wrong Username or Password</H2>";
}
?>