Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    50
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question header location problem

    This is my code to redirect to a different page when a row is deleted:

    <?
    session_start();
    if($_SESSION[count]!==1){header("Location:http://www.mysite.com/mainsite/LoginReg/Login/loginform.php");};

    $surity=$_POST['surity'];
    echo"$surity";
    mysql_connect('localhost', 'user', 'password') or die (mysql_error());
    mysql_select_db('mydb') or die (mysql_error());

    if($surity=yes){
    $sql="DELETE FROM table WHERE Username='$_SESSION[username]' AND Password='$_SESSION[password]'";
    mysql_query($sql);
    header("location:http://www.mysite.com/mainsite/DelAcc/accdeleted.php");
    }else{header("location:http://www.mysite.com/mainsite/DelAcc/accnotdeleted.php");};
    mysql_close();
    ?>

    But i am getting following error:
    Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/mainsite/DelAcc/delaccscript.php:6) in /home/user/public_html/mainsite/DelAcc/delaccscript.php on line 13

    Please tell me where the problem is?
    Last edited by sunnynosid; 02-26-2012 at 05:39 AM.

  • #2
    Regular Coder
    Join Date
    Sep 2010
    Posts
    331
    Thanks
    9
    Thanked 6 Times in 6 Posts
    1) Please remember to use the code/php tags

    2) Your getting that error because header() must be called before any actual output is sent. (i.e echo)
    Coding is a challenge, get used to it
    Always remember to debug
    Try the guess & check method
    Break it down into simple steps

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,354
    Thanks
    61
    Thanked 529 Times in 516 Posts
    You also need a space after Location: like this:
    Location: <url>
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •