我在php('login.php)中创建了一个登录页面,可以正常离线工作。但是当我把它上线时,登录失败了。但是,其他页面无缝连接到同一个数据库,我从中提取登录详细信息。这是登录页面上的代码:
<form action="test.php" method= "post" >
<table>
<tr>
<td colspan="4" align="left"><h1>Insert New User</h1></td>
</tr>
<tr>
<td><input type="text" name="user_name"/></td>
<td><input type="text" name="user_pass"/></td>
<td><input type="submit" name="add_user" value="Add User" /></td>
</tr>
</table>
</form>
<?php
include("includes/db.php");
if(isset($_POST['add_user'])){
$new_name = $_POST['user_name'];
$new_pass = $_POST['user_pass'];
$insert_user = "insert into admin (admin_name,admin_pass) values ('$new_name', '$new_pass')";
$run_user = mysqli_query($con,$insert_user);
if($run_user){
echo "<script>alert('New User Added!')</script>";
echo "<script>window.open('test.php','_self')</script>";
}
}
?>
但每次我尝试使用正确的用户名和密码输入时,都会收到登录错误消息。最初我认为这是一个数据库错误,所以我使用以下代码创建了这个'test.php'页面:
select FK_column from FK_table
WHERE FK_column NOT IN
(SELECT PK_column from PK_table)
这个'test.php'页面连接得很好,甚至可以将数据插入到表中。表结构在线和离线都相同。其他用户登录页面也都正常工作!
答案 0 :(得分:0)
首先,如果您不确定错误,请使用错误报告功能:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>
启动会话功能可能在此处产生问题。尝试移动
session_start();
在输出任何其他文本之前,功能到页面顶部。希望这可以解决它。