php - MySQL 查询在本地主机上工作正常,但在服务器上不行

标签 php mysql sql

我的查询在本地主机上运行得非常好,但是 当我在服务器上执行此操作时,查询成功通过,但是 它将我自己重定向到 login.php 并显示登录查询,而不是转到welcome.php页面

假设 当我输入用户名/密码时,它会将自己重定向到 login.php 成功的 MySQL 语法查询.. 并在屏幕上显示查询

就像我的用户名是 v@v.com 密码v 然后按下登录按钮后,它会将我重定向到login.php,而不是welcome.php,在屏幕上显示类似此查询的查询

SELECT * FROM members WHERE username = 'v@v.com' AND pas = '7a38d8cbd20d9932ba948efaa364bb62651d5ad4'

这是我的代码“login.php”

<?php
        //Start session
        session_start();

        //Connect to mysql server
        include('config.php');




        function clean($str) {
            $str = @trim($str);
            if(get_magic_quotes_gpc()) {
                $str = stripslashes($str);
            }
            return mysql_real_escape_string($str);
        }
        $a = clean($_POST['username']);
        $password = clean($_POST['password1']);
         $passwordx= sha1($password); 





        //Create query
        $qry="SELECT * FROM members WHERE username = '$a' AND pas= '$passwordx'";
        $result=mysql_query($qry);
        echo $qry;
        //Check whether the query was successful or not
        if($result) {
            if(mysql_num_rows($result) > 0) {
                //Login Successful
                session_regenerate_id();
                $member = mysql_fetch_assoc($result);
                $_SESSION['SESS_MEMBER_ID'] = $member['id'];
                $_SESSION['SESS_FIRST_NAME'] = $member['fname'];

                $number=$member['number'];

                if($number=='1')
                {
                mysql_query("UPDATE members SET number=number+1 WHERE id='".$_SESSION['SESS_MEMBER_ID'] ."'  ") ;           
                header("location: info.php");
                exit();
                }
                else
                {
                header("location: welcome.php");
                exit();
                }

            exit();
            } elseif(mysql_num_rows($result) == 0){

                header("location: error.php");
                exit();
            }
        } else {
            header("location: error.php");
            exit();
        }
    ?>

有人能发现错误吗?

最佳答案

这个:echo $qry;

一旦执行此操作,您将无法使用 header() 进行重定向。

来自文档 (http://php.net/manual/en/function.header.php):

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.

关于php - MySQL 查询在本地主机上工作正常,但在服务器上不行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25442483/

相关文章:

php - PHP 中两个日期之间的完整天数?

php - 框架更新你要等多久?

php - 将一个选择选项的值用于另一个选择的 sql where 子句

PHP图像缩略图性能?

java - 是否可以使用 Hibernate 将一个 Java 对象映射到具有 FK 关系的多个表?

php - CodeIgniter 3:错误编号2014命令不同步;您现在不能运行此命令

mysql - SQL 通过带有 where 或子句的连接表进行选择

mysql - 优化 SQL 查询

php - 如何知道是否插入了新行,或者是否更新了现有行?

mysql - 扩展以根据数据范围选择