gpt4 book ai didi

php - 登录信息页面未重定向

转载 作者:行者123 更新时间:2023-11-29 22:24:05 24 4
gpt4 key购买 nike

在提交正确的用户名/密码后,我无法将代码重定向到另一个页面。输入用户名/密码并点击提交后,页面不会重定向。

页面只是重新加载并清除字段输入(即使它是粘性表单),并保持在同一页面,除了 URL 将 ?submit=Submit 添加到 URL 末尾。 .

我没有收到任何 mysql 错误 - 数据库在与用户名/密码组合匹配的行似乎正在经历的查询中连接良好。

它应该循环访问数据库,检查用户名/密码组合是否存在,然后重定向到指定页面。我不确定我在这里没有看到/缺少什么,导致页面无法重定向。任何投入将不胜感激。

PHP:

<?php
define('DB_LOCATION', 'x');
define('DB_USERNAME', 'x');
define('DB_PASS', 'x');
define('DB_NAME', 'x');

$dbc = mysqli_connect(DB_LOCATION, DB_USERNAME, DB_PASS, DB_NAME)
or die('Error connecting to database');

$error_message= "";

if (isset($_POST['submit'])) {

$user_name = $_POST['user'];
$user_password= $_POST['pass'];


// ADD QUERY TO CHECK IF USER/PASS COMBO IS CORRECT
if(!empty($user_name) && !empty($user_password)) {

$query = "SELECT * FROM employees WHERE username='$user_name' and password='$user_password'";

$result = mysqli_query($dbc, $query)
or die ('Error querying username/password request');

if(mysqli_num_rows($result) == 1) {

$user_name = $row['user'];
$user_password = $row['pass'];

header("Location: www.mysite.com ");

} // end if rows

else {
$error_message = "You were not able to log in";
} // end else


} // end query


} // end isset

?>

HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
<link type="text/css" rel="stylesheet" href="/LESSON5/5_Signup_CSS.css">

</head>
<body>
<h1>Welcome to my website!</h1>
<h2>Please login below.</h2>
<h3>Don't have an account? <a href="/LESSON5/2%20-%20CREATE%20AN%20ACCOUNT.php">Create one here.</a></h3>

<div class="formFormat" >
<div id="table1">
<form name =loginForm method="post" action="<?php echo $_SERVER[' PHP_SELF' ];?>">
<table id="cssTable">
<tr>
<td>Username:</td><td><input type="text" id="user" name="user" value="<?php echo $user_name ?>" /></td>
</tr>
<tr>
<td>Password:</td><td><input type="text" id="pass" name="pass" value="<?php echo $user_password ?>"/></td>
</tr>
</table>
</form>
</div>

<div id="table2">
<form>
<table>
<tr>
<td><input type="submit" name="submit"/></td>
</tr>
<tr>
<td id="createAccount"><a href="/LESSON5/2%20-%20CREATE%20AN%20ACCOUNT.php">Create an account</a></td>
</tr>
<tr>
<td><?php echo $error_message ?></td>
</tr>

</table>
</form>
</form>
</div>
</div>

<?php
mysqli_close($dbc);
?>

</body>
</html>

最佳答案

删除<form> ,就在 <div id="table2"> 之前,和</form>也是如此。

关于php - 登录信息页面未重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30428657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com