简体   繁体   English

MySQL查询可以在本地主机上正常运行,但不能在服务器上运行

[英]MySQL query Working fine on localhost but not on server

My query is working absolutely fine on localhost but when i execute this on server the query successfully passed but it redirect myself to login.php and shows login query instead going on welcome.php page 我的查询在localhost上运行正常,但是当我在服务器上执行此查询时,查询成功通过,但是将自己重定向到login.php并显示登录查询,而不是在welcome.php页面上

suppose when i enter username/password it redirect myself to login.php with the successful MySQL syntax query.. and query shows on the screen 假设当我输入用户名/密码时,它将使用成功的MySQL语法查询将自己重定向到login.php。并且查询显示在屏幕上

like my username is v@v.com password v then after pressing login button it redirect me to login.php instead of welcome.php showing query like this query on the screen 像我的用户名是v@v.com密码v,然后按登录按钮后,它将我重定向到login.php而不是welcome.php在屏幕上显示类似此查询的查询

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

this is my code "login.php" 这是我的代码“ 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();
        }
    ?>

can someone spot the mistake? 有人可以发现错误吗?

This: echo $qry; 这个: echo $qry;

Once you do that, you cannot redirect using header() . 一旦这样做,就无法使用header()重定向。

From the documentation ( http://php.net/manual/en/function.header.php ): 从文档( http://php.net/manual/zh/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. 请记住,必须先通过常规HTML标记,文件中的空白行或从PHP发送任何实际输出,然后调用header()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP Excel 导入到 MYSQL 数据库在本地主机上工作正常,但在在线服务器上不能正常工作 - PHP Excel import to MYSQL database working fine on localhost but not on online server 会话在本地主机上工作正常但在服务器上不工作 - Session in working fine in localhost but not at server Phpmailer 在 localhost 中工作正常但不在服务器中 - Phpmailer working fine in localhost But not in server fullcalendar在localhost中工作正常,但在服务器中工作不正常 - fullcalendar is working fine in localhost but not in server $ .post和AJAX不能在服务器上运行,但在localhost中工作正常 - $.post & AJAX is not working on server, but working fine in localhost SMTP邮件无法在服务器上正常工作在本地主机上 - SMTP Mail Not Working ON Server Working Fine On Localhost javascript在localhost上工作正常,但在实时服务器上却不能 - javascript working fine in localhost but not on live server Wamp Server 3.0.6可以正常工作,但不能在网络上运行 - Wamp Server 3.0.6 working fine as localhost, but not on network 页面在本地主机上运行良好但未在托管服务器上运行 - Pages are working fine on localhost but not running on the hosting server CodeIgniter邮件无法在服务器上运行,但可以在本地主机上正常工作 - CodeIgniter mail not working on server but works fine localhost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM