php - 无法访问获取 dBase 数据。登录页面不断循环回到同一页面

标签 php html mysql mysql-error-1064

每次我尝试通过 webhost/adminlogin.php 登录时,我都会被重定向回同一页面。有什么我忘了补充的吗?谢谢你的帮助。下面是我的脚本

这是我的adminlogin.php

<?php session_start(); if(isset($_SESSION[ 'admin_login'])) header( 'location:admin_homepage.php'); ?>

<!DOCTYPE html>
<html>

<head>
  <noscript>
    <meta http-equiv="refresh" content="0;url=no-js.php">
  </noscript>
  <meta charset="UTF-8">
  <title>Admin Login - Online Banking</title>

  <link rel="stylesheet" href="newcss.css">
</head>
<?php include 'header.php'; ?>

<div class='content'>
  <div class="user_login">
    <form action='' method='POST'>
      <table align="center">
        <tr>
          <td><span class="caption">Admin Login</span>
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <hr>
          </td>
        </tr>
        <tr>
          <td>Username:</td>
        </tr>
        <tr>
          <td>
            <input type="text" name="uname" required>
          </td>
        </tr>
        <tr>
          <td>Password:</td>
        </tr>
        <tr>
          <td>
            <input type="password" name="pwd" required>
          </td>
        </tr>
        <tr>
          <td class="button1">
            <input type="submit" name="submitBtn" value="Log In" class="button">
          </td>
        </tr>
      </table>
    </form>
  </div>
</div>

<?php include 'footer.php'; ?>
<?php include '_inc/dbconn.php'; if(!isset($_SESSION[ 'admin_login'])){ if(isset($_REQUEST[ 'submitBtn'])){ $sql="SELECT * FROM admin WHERE id='1'" ; $result=mysql_query($sql); $rws=m ysql_fetch_array($result); $username=m ysql_real_escape_string($_REQUEST[
'uname']); $password=m ysql_real_escape_string($_REQUEST[ 'pwd']); if($username==$rws[8] && $password==$rws[9]) { $_SESSION[ 'admin_login']=1; header( 'location:admin_hompage.php'); } else header( 'location:adminlogin.php'); } } else { header(
'location:admin_hompage.php'); } ?>

最佳答案

我认为您的脚本可能存在一些问题。一个明显的问题是,在发送脚本底部的 header 之前,您正在输出 html 内容。

HTTP header 必须在任何其他内容之前发送到客户端。

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

我会建议,除非你需要继续处理。您将所有登录代码移至脚本顶部并调用“exit()”;在您将 header 发送到客户端以防止任何进一步处理或将内容发送到客户端之后。

关于php - 无法访问获取 dBase 数据。登录页面不断循环回到同一页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32701704/

相关文章:

php - 从我的 $_POST 获取同一行中的另一个值

php - Laravel 查询关系

php - Javascript 原型(prototype)是否类似于 PHP 静态方法?

javascript - 未捕获的类型错误 : Failed to execute 'readAsBinaryString' on 'FileReader' : parameter 1 is not of type 'Blob'

php - 复制行,同时忽略基于特定列的重复项

java - 我的 java 程序没有正确计算数据库行数

php - Return redirect() 没有将我带到所需的方法

javascript - 如何使用 PHP 将数据保存在我的数据库中

javascript - 网页中调用的css和javaScript文件是什么?

php - 需要帮助使用 MAMP 调试 CakePHP 与 MySQL 的连接,错误 : missing table in database (for what seems like no reason)