Shows warning need help..

Discussion in 'PHP' started by secret90, Aug 20, 2008.

  1. #1
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
      <title>Check Login Info!</title>
    </head>
    
    <body>
    
    <?php
    require("connect.php");
    
    $username=$_POST['username'];
    $password=$_POST['password'];
    $username = stripslashes($username);
    $password = stripslashes($password);
    $username = mysql_real_escape_string($username);
    $password = mysql_real_escape_string($password);
    
    
    
    $sql = "SELECT * FROM register WHERE Username='$username' AND Password='$password'";
    $result = mysql_query($sql);
    
    $count = mysql_num_rows($result);
    if($count==1)
    {
        echo "Welcome $username !";
        header('Location:success.php');
    }
    else
    {
    echo "Wrong Username or Password";
    exit();
    }
    
    if (!mysql_query($sql,$con))
      {
           die('Error: ' . mysql_error());
      }
    
    mysql_close($con);
    
    ?>
    
    </body>
    
    </html>
    
    
    Code (markup):
    and it says

    Welcome faisal !
    Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\final_project\check_login.php:12) in c:\program files\easyphp1-8\www\final_project\check_login.php on line 31
    
    Code (markup):
    i want that when the login is successfull a new page is open and also at this page welcome "username" is shown like yahoo.

    any one plz check this script and do wat i need.
    thanks in advance.
     
    secret90, Aug 20, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    www.php.net/header
     
    nico_swd, Aug 21, 2008 IP
  3. nice.wallpapers

    nice.wallpapers Active Member

    Messages:
    142
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Hi,

    Error code:
    <?php
    print “text”;
    header(’Location: http://www.example.com/’);
    ?>
    Php show error when you print any thing before this redirection.

    Solution:
    I am giving you a javascript + php function that will do redirection job:

    <?php
    function FunJavaScriptRedirection($url)
    {?>
    <script type=”text/javascript”>
    <!–
    window.location = “<?=$url?>”
    //–>
    </script>
    <?}
    print “test”;
    FunJavaScriptRedirection(”http://www.example.com/”);

    ?>

    Thanks :)
     
    nice.wallpapers, Aug 21, 2008 IP
  4. William[ws]

    William[ws] Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That will getter done for you . instead of using a javascript redirect
    
    <?php
    require("connect.php");
    
    $username=$_POST['username'];
    $password=$_POST['password'];
    $username = stripslashes($username);
    $password = stripslashes($password);
    $username = mysql_real_escape_string($username);
    $password = mysql_real_escape_string($password);
    
    
    
    $sql = "SELECT * FROM register WHERE Username='$username' AND Password='$password'";
    $result = mysql_query($sql);
    
    $count = mysql_num_rows($result);
    if($count==1)
    {
        echo "Welcome $username !";
        header('Location:success.php');
    }
    else
    {
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
      <title>Check Login Info!</title>
    </head>
    
    <body>
    Wrong Username or Password
    <?
    if (!mysql_query($sql,$con))
      {
           die('Error: ' . mysql_error());
      }
    exit();
    }
    
    mysql_close($con);
    
    ?>
    
    </body>
    
    </html>
    
    PHP:
     
    William[ws], Aug 21, 2008 IP
  5. secret90

    secret90 Guest

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    still says,

    Welcome faisal !
    Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\final_project\check_login.php:19) in c:\program files\easyphp1-8\www\final_project\check_login.php on line 20

    ???????????????
     
    secret90, Aug 21, 2008 IP
  6. secret90

    secret90 Guest

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i have correct this.

    i use ob_start() just after the require();
    and ob_end_flush just after header();

    thankz for replyz men..
     
    secret90, Aug 21, 2008 IP
  7. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #7
    This is a bad solution. You should find the reason instead of just ignoring it.
     
    mwasif, Aug 21, 2008 IP
  8. William[ws]

    William[ws] Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Yea agreed with mwasif..

    I see the problem put

    exit(); after
    header('Location:success.php');

    so

    header('Location:success.php');
    exit();
     
    William[ws], Aug 21, 2008 IP
  9. secret90

    secret90 Guest

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    thanks for the information mwasif, if u didn't tell me i will do same thing next time whenever i have that type of problem.
     
    secret90, Aug 21, 2008 IP
  10. secret90

    secret90 Guest

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    There is no need to find a solution.
    William[ws] already rectified and it works
    thanks man.
     
    secret90, Aug 21, 2008 IP
  11. William[ws]

    William[ws] Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    No problemo!
     
    William[ws], Aug 22, 2008 IP
  12. ghprod

    ghprod Active Member

    Messages:
    1,010
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    78
    #12
    nice to hear u r done :)
     
    ghprod, Aug 22, 2008 IP