当我提交表单时,我登陆login.php并收到很多错误。
我在以下链接上添加了错误: https://docs.google.com/document/d/1AqwZ71iAQgZGMU-W0Go6czbpgGenF_f7ucgmEFw0AHo/edit
我是新手,并且使用上面的代码在最后5个小时内挣扎。 我的登录注销系统中有以下页面:
db.php中
<?php
$conn=new mysqli('localhost','root','','people');
?>
的index.php
<?php
session_start();
?>
<html>
<head></head>
<body>
<form method="post" name="login" action="login.php">
<label for="name" class="labelname"> Username </label>
<input type="text" name="username" id="userid" required="required" /><br />
<label for="name" class="labelname"> Password </label>
<input type="password" name="password" id="passid" required="required" /><br />
<input type="submit" name="submit" id="submit" value="Login" />
</form>
</body>
</html>
的login.php
<?php
include('db.php');
session_start();
{
$user=mysqli_real_escape_string($_POST['username']);
$pass=mysqli_real_escape_string($_POST['password']);
$fetch=mysqli_query("SELECT id FROM `user` WHERE
username='$user' and password='$pass'");
$count=mysqli_num_rows($fetch);
if($count!="")
{
session_register("sessionusername");
$_SESSION['login_username']=$user;
header("Location:profile.php");
}
else
{
header('Location:index.php');
}}
?>
logout.php
<?php
session_start();
if(session_destroy())
{
header("Location: index.php");
}
?>
session.php文件
<?php
include('db.php');
session_start();
$check=$_SESSION['login_username'];
$session=mysqli_query("SELECT username FROM `user` WHERE username='$check' ");
$row=mysqli_fetch_array($session);
$login_session=$row['username'];
if(!isset($login_session))
{
header("Location:index.php");
}
?>
profile.php
<?php
include('db.php');
session_start();
$check=$_SESSION['login_username'];
$session=mysqli_query("SELECT username FROM `user` WHERE username='$check' ");
$row=mysqli_fetch_array($session);
$login_session=$row['username'];
if(!isset($login_session))
{
header("Location:index.php");
}
?>
答案 0 :(得分:0)
我认为你的db.php文件有问题。 您只应传递3个参数,即服务器名,用户名和密码,而我看到您传递的是4个,其中一个是空白的。
请检查是否
<?php
$ conn = new mysqli('localhost','root','people'); ?&GT;
或
<?php
$ conn = new mysqli('localhost','',''); ?&GT;
作品。