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.

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里