dongmuyuan3046 2014-08-22 08:14
浏览 30
已采纳

MySQL查询在localhost上工作正常但在服务器上没有

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

suppose when i enter username/password it redirect myself to login.php with the successful MySQL syntax query.. and query shows on the screen

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

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

this is my code "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?

  • 写回答

1条回答 默认 最新

  • duanaixuan7385 2014-08-22 08:24
    关注

    This: echo $qry;

    Once you do that, you cannot redirect using header().

    From the documentation (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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致