1

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 [email protected] 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 = '[email protected]' 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?

5
  • check in your database of server if username with that password exists ? Commented Aug 22, 2014 at 8:21
  • why this echo $qry; in the code? Commented Aug 22, 2014 at 8:22
  • @arunrc to check the syntax of query. Commented Aug 22, 2014 at 8:22
  • Then the header won't work.. Header must be before echo Commented Aug 22, 2014 at 8:25
  • @TBI yes it is, actually the query is passing successfully. After executing this query my session is started, but it leaves a query behind it. after clicking on login button i am getting this Query on login.php pae say(xyz.com/login.php)but wen i type (xyz.com/welcome.php) den i can access my account.. Commented Aug 22, 2014 at 8:27

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

then why it is working on localhost(wamp) so well, and if i cant then what's the solution to solve this?
Remove the echo statement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.