[PHP] Header problem

Ask a Question related to Macromedia Dynamic HTML, Design and Development.

  1. #1

    Default [PHP] Header problem

    Hey again, im trying to redirect the user to another page after a succesful
    INSERT into a database,
    by using the header(); function and i get the following message

    Warning: Cannot modify header information - headers already sent by (output
    started at c:\htdocs\site_test\register.php:59) in
    c:\htdocs\site_test\register.php on line 74

    Its a self processing form. I made it like that so users wont have to go
    back and forth between pages to enter information could that be causing the
    problem?
    What should i use to redirect the users to the success.php page

    i originally tried

    header("Refresh: 2; URL=success.php");
    header("Location: success.php");

    but both got the same problem

    Thanks in advance


    ....hooligan Guest

  2. Similar Questions and Discussions

    1. DG Header renderer problem
      I've also stumbled upon this issue, the problem occurs when the data grid is using variable row heights. here's an example with the problem...
    2. #39019 [NEW]: Header And Location Problem
      From: bojan dot saksida at volja dot net Operating system: Windows XP PHP version: 6CVS-2006-10-02 (snap) PHP Bug Type: ...
    3. header problem
      Hi I have 2 sites 1 uses php 4.0.6 (old i know but not possible to have it upgraded.) the other uses 4.3.7 (soon 4.3.8) Now on 4.3.7 i use...
    4. Problem with including a header
      I have the following file structure: / header.asp test.asp /subDir testpage.asp /images I would like to have header.asp to be usable from...
    5. set header problem
      Hi All Response.setHeader("Content-disposition", "attachment; filename="+ fileName + strExt); works for IE 5.5 but not in netscape . IE 5.5...
  3. #2

    Default Re: [PHP] Header problem

    This is a common problem. The headers have to be sent *before* everything
    else -- if you've sent any HTML at all, even just a line break or a bit of
    white space somewhere, the headers won't send. So just make sure the headers
    get sent by a PHP block that appears before the opening HTML tag.

    Location is the best redirection header to use...


    .....hooligan wrote:
    > Hey again, im trying to redirect the user to another page after a
    > succesful INSERT into a database,
    > by using the header(); function and i get the following message
    >
    > Warning: Cannot modify header information - headers already sent by
    > (output started at c:\htdocs\site_test\register.php:59) in
    > c:\htdocs\site_test\register.php on line 74
    >
    > Its a self processing form. I made it like that so users wont have to
    > go back and forth between pages to enter information could that be
    > causing the problem?
    > What should i use to redirect the users to the success.php page
    >
    > i originally tried
    >
    > header("Refresh: 2; URL=success.php");
    > header("Location: success.php");
    >
    > but both got the same problem
    >
    > Thanks in advance

    rob::db Guest

  4. #3

    Default Re: [PHP] Header problem

    The header is in the php tags before the <html> tags and it still happens.
    Is it something im setting in the top php tags that stuffs me up
    Heres what in the opening php tags. The header appears down the bottom of it

    <?php
    include "inc.conn.php";
    if(isset($_POST['submit']) && $_POST['submit'] == "Submit") {
    $emailPattern = '/^\w[-.\w]*@([-a-z0-9]+\.)+[a-z]{2,4}$/i';
    $error1 = "";
    $error2 = "";
    $error3 = "";
    $username = $_POST['username'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $confpassword = $_POST['confpassword'];
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $address = $_POST['address'];
    $suburb = $_POST['suburb'];
    $city = $_POST['city'];
    $postcode = $_POST['postcode'];
    $gender = $_POST['gender'];
    $country = $_POST['country'];

    if (empty($username)) {
    $error1 .= "<tr align=\"center\"><td class=\"error\">You must enter a
    username</td></tr>";
    }
    if (empty($email)) {
    $error1 .= "<tr align=\"center\"><td class=\"error\">You must enter a
    email address</td></tr>";
    }else if(!preg_match($emailPattern,$email)) {
    $error1 .= "<tr align=\"center\"><td class=\"error\">Invalid email
    address</td></tr>";
    }
    if (empty($password)) {
    $error1 .= "<tr align=\"center\"><td class=\"error\">You must enter a
    password</td></tr>";
    }
    if (empty($confpassword)) {
    $error1 .= "<tr align=\"center\"><td class=\"error\">You must enter a
    confirm password</td></tr>";
    }
    if(isset($password) && isset($confpassword)) {
    if($password != $confpassword) {
    $error1 .= "<tr align=\"center\"><td class=\"error\">Confirm Password
    must match Password feild</td></tr>";
    $password = "";
    $confpassword = "";
    }
    }
    if (empty($firstname)) {
    $error2 .= "<tr align=\"center\"><td class=\"error\">You must enter your
    first name</td></tr>";
    }
    if (empty($lastname)) {
    $error2 .= "<tr align=\"center\"><td class=\"error\">You must enter your
    last name</td></tr>";
    }
    if (empty($address)) {
    $error3 .= "<tr align=\"center\"><td class=\"error\">You must enter your
    email address</td></tr>";
    }
    if (empty($suburb)) {
    $error3 .= "<tr align=\"center\"><td class=\"error\">You must enter your
    suburb</td></tr>";
    }
    if (empty($city)) {
    $error3 .= "<tr align=\"center\"><td class=\"error\">You must enter your
    city</td></tr>";
    }
    if (empty($country)) {
    $error3 .= "<tr align=\"center\"><td class=\"error\">You must enter your
    country</td></tr>";
    }

    if(isset($error1)) {
    echo "<table width=\"300\" border=\"1\" align=\"center\"
    bordercolor=\"#000000\">" . $error1 . "</table>";
    }

    if (empty($error1) && empty($error2) && empty($error3)) {
    $sql = "SELECT user_name " .
    "FROM members " .
    "WHERE user_name = '$username'";
    $result = mysql_query($sql)
    or die(mysql_error());

    if(mysql_num_rows($result) == 0) {
    $sql = "INSERT INTO members (user_name, password, email, first_name,
    last_name, gender, address, suburb, city, postcode, country) " .
    "VALUES ('$username', PASSWORD('$password'), '$email', '$firstname',
    '$lastname', '$gender', '$address', '$suburb', '$city', '$postcode',
    '$country');";
    $result = mysql_query($sql)
    or die(mysql_error());
    header("Location:sendconf.php");
    } else {
    echo "<p align=\"center\" class=\"black\">Username \"" . $username . "\"
    is already taken</p>";
    $username = "";
    }
    }
    }
    ?>

    "rob::db" <rob@digitalburn.net> wrote in message
    news:d8o1iq$kcl$1@forums.macromedia.com...
    > This is a common problem. The headers have to be sent *before* everything
    > else -- if you've sent any HTML at all, even just a line break or a bit of
    > white space somewhere, the headers won't send. So just make sure the
    > headers
    > get sent by a PHP block that appears before the opening HTML tag.
    >
    > Location is the best redirection header to use...
    >
    >
    > ....hooligan wrote:
    >> Hey again, im trying to redirect the user to another page after a
    >> succesful INSERT into a database,
    >> by using the header(); function and i get the following message
    >>
    >> Warning: Cannot modify header information - headers already sent by
    >> (output started at c:\htdocs\site_test\register.php:59) in
    >> c:\htdocs\site_test\register.php on line 74
    >>
    >> Its a self processing form. I made it like that so users wont have to
    >> go back and forth between pages to enter information could that be
    >> causing the problem?
    >> What should i use to redirect the users to the success.php page
    >>
    >> i originally tried
    >>
    >> header("Refresh: 2; URL=success.php");
    >> header("Location: success.php");
    >>
    >> but both got the same problem
    >>
    >> Thanks in advance
    >
    >

    ....hooligan Guest

  5. #4

    Default Re: [PHP] Header problem

    Have you got a space in the file before the first PHP tag opens?


    .....hooligan wrote:
    > The header is in the php tags before the <html> tags and it still
    > happens. Is it something im setting in the top php tags that stuffs
    > me up
    > Heres what in the opening php tags. The header appears down the
    > bottom of it
    >
    > <?php
    > include "inc.conn.php";
    > if(isset($_POST['submit']) && $_POST['submit'] == "Submit") {
    > $emailPattern = '/^\w[-.\w]*@([-a-z0-9]+\.)+[a-z]{2,4}$/i';
    > $error1 = "";
    > $error2 = "";
    > $error3 = "";
    > $username = $_POST['username'];
    > $email = $_POST['email'];
    > $password = $_POST['password'];
    > $confpassword = $_POST['confpassword'];
    > $firstname = $_POST['firstname'];
    > $lastname = $_POST['lastname'];
    > $address = $_POST['address'];
    > $suburb = $_POST['suburb'];
    > $city = $_POST['city'];
    > $postcode = $_POST['postcode'];
    > $gender = $_POST['gender'];
    > $country = $_POST['country'];
    >
    > if (empty($username)) {
    > $error1 .= "<tr align=\"center\"><td class=\"error\">You must
    > enter a username</td></tr>";
    > }
    > if (empty($email)) {
    > $error1 .= "<tr align=\"center\"><td class=\"error\">You must
    > enter a email address</td></tr>";
    > }else if(!preg_match($emailPattern,$email)) {
    > $error1 .= "<tr align=\"center\"><td class=\"error\">Invalid email
    > address</td></tr>";
    > }
    > if (empty($password)) {
    > $error1 .= "<tr align=\"center\"><td class=\"error\">You must
    > enter a password</td></tr>";
    > }
    > if (empty($confpassword)) {
    > $error1 .= "<tr align=\"center\"><td class=\"error\">You must
    > enter a confirm password</td></tr>";
    > }
    > if(isset($password) && isset($confpassword)) {
    > if($password != $confpassword) {
    > $error1 .= "<tr align=\"center\"><td class=\"error\">Confirm
    > Password must match Password feild</td></tr>";
    > $password = "";
    > $confpassword = "";
    > }
    > }
    > if (empty($firstname)) {
    > $error2 .= "<tr align=\"center\"><td class=\"error\">You must
    > enter your first name</td></tr>";
    > }
    > if (empty($lastname)) {
    > $error2 .= "<tr align=\"center\"><td class=\"error\">You must
    > enter your last name</td></tr>";
    > }
    > if (empty($address)) {
    > $error3 .= "<tr align=\"center\"><td class=\"error\">You must
    > enter your email address</td></tr>";
    > }
    > if (empty($suburb)) {
    > $error3 .= "<tr align=\"center\"><td class=\"error\">You must
    > enter your suburb</td></tr>";
    > }
    > if (empty($city)) {
    > $error3 .= "<tr align=\"center\"><td class=\"error\">You must
    > enter your city</td></tr>";
    > }
    > if (empty($country)) {
    > $error3 .= "<tr align=\"center\"><td class=\"error\">You must
    > enter your country</td></tr>";
    > }
    >
    > if(isset($error1)) {
    > echo "<table width=\"300\" border=\"1\" align=\"center\"
    > bordercolor=\"#000000\">" . $error1 . "</table>";
    > }
    >
    > if (empty($error1) && empty($error2) && empty($error3)) {
    > $sql = "SELECT user_name " .
    > "FROM members " .
    > "WHERE user_name = '$username'";
    > $result = mysql_query($sql)
    > or die(mysql_error());
    >
    > if(mysql_num_rows($result) == 0) {
    > $sql = "INSERT INTO members (user_name, password, email,
    > first_name, last_name, gender, address, suburb, city, postcode,
    > country) " . "VALUES ('$username', PASSWORD('$password'),
    > '$email', '$firstname', '$lastname', '$gender', '$address',
    > '$suburb', '$city', '$postcode', '$country');";
    > $result = mysql_query($sql)
    > or die(mysql_error());
    > header("Location:sendconf.php");
    > } else {
    > echo "<p align=\"center\" class=\"black\">Username \"" .
    > $username . "\" is already taken</p>";
    > $username = "";
    > }
    > }
    > }
    >>
    >
    > "rob::db" <rob@digitalburn.net> wrote in message
    > news:d8o1iq$kcl$1@forums.macromedia.com...
    >> This is a common problem. The headers have to be sent *before*
    >> everything else -- if you've sent any HTML at all, even just a line
    >> break or a bit of white space somewhere, the headers won't send. So
    >> just make sure the headers
    >> get sent by a PHP block that appears before the opening HTML tag.
    >>
    >> Location is the best redirection header to use...
    >>
    >>
    >> ....hooligan wrote:
    >>> Hey again, im trying to redirect the user to another page after a
    >>> succesful INSERT into a database,
    >>> by using the header(); function and i get the following message
    >>>
    >>> Warning: Cannot modify header information - headers already sent by
    >>> (output started at c:\htdocs\site_test\register.php:59) in
    >>> c:\htdocs\site_test\register.php on line 74
    >>>
    >>> Its a self processing form. I made it like that so users wont have
    >>> to go back and forth between pages to enter information could that
    >>> be causing the problem?
    >>> What should i use to redirect the users to the success.php page
    >>>
    >>> i originally tried
    >>>
    >>> header("Refresh: 2; URL=success.php");
    >>> header("Location: success.php");
    >>>
    >>> but both got the same problem
    >>>
    >>> Thanks in advance

    rob::db Guest

  6. #5

    Default Re: [PHP] Header problem

    Nope no white space? Anything else it could be?

    "rob::db" <rob@digitalburn.net> wrote in message
    news:d8o4a2$nem$1@forums.macromedia.com...
    > Have you got a space in the file before the first PHP tag opens?
    >
    >
    > ....hooligan wrote:
    >> The header is in the php tags before the <html> tags and it still
    >> happens. Is it something im setting in the top php tags that stuffs
    >> me up
    >> Heres what in the opening php tags. The header appears down the
    >> bottom of it
    >>
    >> <?php
    >> include "inc.conn.php";
    >> if(isset($_POST['submit']) && $_POST['submit'] == "Submit") {
    >> $emailPattern = '/^\w[-.\w]*@([-a-z0-9]+\.)+[a-z]{2,4}$/i';
    >> $error1 = "";
    >> $error2 = "";
    >> $error3 = "";
    >> $username = $_POST['username'];
    >> $email = $_POST['email'];
    >> $password = $_POST['password'];
    >> $confpassword = $_POST['confpassword'];
    >> $firstname = $_POST['firstname'];
    >> $lastname = $_POST['lastname'];
    >> $address = $_POST['address'];
    >> $suburb = $_POST['suburb'];
    >> $city = $_POST['city'];
    >> $postcode = $_POST['postcode'];
    >> $gender = $_POST['gender'];
    >> $country = $_POST['country'];
    >>
    >> if (empty($username)) {
    >> $error1 .= "<tr align=\"center\"><td class=\"error\">You must
    >> enter a username</td></tr>";
    >> }
    >> if (empty($email)) {
    >> $error1 .= "<tr align=\"center\"><td class=\"error\">You must
    >> enter a email address</td></tr>";
    >> }else if(!preg_match($emailPattern,$email)) {
    >> $error1 .= "<tr align=\"center\"><td class=\"error\">Invalid email
    >> address</td></tr>";
    >> }
    >> if (empty($password)) {
    >> $error1 .= "<tr align=\"center\"><td class=\"error\">You must
    >> enter a password</td></tr>";
    >> }
    >> if (empty($confpassword)) {
    >> $error1 .= "<tr align=\"center\"><td class=\"error\">You must
    >> enter a confirm password</td></tr>";
    >> }
    >> if(isset($password) && isset($confpassword)) {
    >> if($password != $confpassword) {
    >> $error1 .= "<tr align=\"center\"><td class=\"error\">Confirm
    >> Password must match Password feild</td></tr>";
    >> $password = "";
    >> $confpassword = "";
    >> }
    >> }
    >> if (empty($firstname)) {
    >> $error2 .= "<tr align=\"center\"><td class=\"error\">You must
    >> enter your first name</td></tr>";
    >> }
    >> if (empty($lastname)) {
    >> $error2 .= "<tr align=\"center\"><td class=\"error\">You must
    >> enter your last name</td></tr>";
    >> }
    >> if (empty($address)) {
    >> $error3 .= "<tr align=\"center\"><td class=\"error\">You must
    >> enter your email address</td></tr>";
    >> }
    >> if (empty($suburb)) {
    >> $error3 .= "<tr align=\"center\"><td class=\"error\">You must
    >> enter your suburb</td></tr>";
    >> }
    >> if (empty($city)) {
    >> $error3 .= "<tr align=\"center\"><td class=\"error\">You must
    >> enter your city</td></tr>";
    >> }
    >> if (empty($country)) {
    >> $error3 .= "<tr align=\"center\"><td class=\"error\">You must
    >> enter your country</td></tr>";
    >> }
    >>
    >> if(isset($error1)) {
    >> echo "<table width=\"300\" border=\"1\" align=\"center\"
    >> bordercolor=\"#000000\">" . $error1 . "</table>";
    >> }
    >>
    >> if (empty($error1) && empty($error2) && empty($error3)) {
    >> $sql = "SELECT user_name " .
    >> "FROM members " .
    >> "WHERE user_name = '$username'";
    >> $result = mysql_query($sql)
    >> or die(mysql_error());
    >>
    >> if(mysql_num_rows($result) == 0) {
    >> $sql = "INSERT INTO members (user_name, password, email,
    >> first_name, last_name, gender, address, suburb, city, postcode,
    >> country) " . "VALUES ('$username', PASSWORD('$password'),
    >> '$email', '$firstname', '$lastname', '$gender', '$address',
    >> '$suburb', '$city', '$postcode', '$country');";
    >> $result = mysql_query($sql)
    >> or die(mysql_error());
    >> header("Location:sendconf.php");
    >> } else {
    >> echo "<p align=\"center\" class=\"black\">Username \"" .
    >> $username . "\" is already taken</p>";
    >> $username = "";
    >> }
    >> }
    >> }
    >>>
    >>
    >> "rob::db" <rob@digitalburn.net> wrote in message
    >> news:d8o1iq$kcl$1@forums.macromedia.com...
    >>> This is a common problem. The headers have to be sent *before*
    >>> everything else -- if you've sent any HTML at all, even just a line
    >>> break or a bit of white space somewhere, the headers won't send. So
    >>> just make sure the headers
    >>> get sent by a PHP block that appears before the opening HTML tag.
    >>>
    >>> Location is the best redirection header to use...
    >>>
    >>>
    >>> ....hooligan wrote:
    >>>> Hey again, im trying to redirect the user to another page after a
    >>>> succesful INSERT into a database,
    >>>> by using the header(); function and i get the following message
    >>>>
    >>>> Warning: Cannot modify header information - headers already sent by
    >>>> (output started at c:\htdocs\site_test\register.php:59) in
    >>>> c:\htdocs\site_test\register.php on line 74
    >>>>
    >>>> Its a self processing form. I made it like that so users wont have
    >>>> to go back and forth between pages to enter information could that
    >>>> be causing the problem?
    >>>> What should i use to redirect the users to the success.php page
    >>>>
    >>>> i originally tried
    >>>>
    >>>> header("Refresh: 2; URL=success.php");
    >>>> header("Location: success.php");
    >>>>
    >>>> but both got the same problem
    >>>>
    >>>> Thanks in advance
    >
    >

    ....hooligan Guest

  7. #6

    Default Re: [PHP] Header problem

    I think i worked it out. It doesnt like this line if(isset($error1)) {

    "....hooligan" <robochippy@aapt.net.au> wrote in message
    news:d8p234$343$1@forums.macromedia.com...
    > Nope no white space? Anything else it could be?
    >
    > "rob::db" <rob@digitalburn.net> wrote in message
    > news:d8o4a2$nem$1@forums.macromedia.com...
    >> Have you got a space in the file before the first PHP tag opens?
    >>
    >>
    >> ....hooligan wrote:
    >>> The header is in the php tags before the <html> tags and it still
    >>> happens. Is it something im setting in the top php tags that stuffs
    >>> me up
    >>> Heres what in the opening php tags. The header appears down the
    >>> bottom of it
    >>>
    >>> <?php
    >>> include "inc.conn.php";
    >>> if(isset($_POST['submit']) && $_POST['submit'] == "Submit") {
    >>> $emailPattern = '/^\w[-.\w]*@([-a-z0-9]+\.)+[a-z]{2,4}$/i';
    >>> $error1 = "";
    >>> $error2 = "";
    >>> $error3 = "";
    >>> $username = $_POST['username'];
    >>> $email = $_POST['email'];
    >>> $password = $_POST['password'];
    >>> $confpassword = $_POST['confpassword'];
    >>> $firstname = $_POST['firstname'];
    >>> $lastname = $_POST['lastname'];
    >>> $address = $_POST['address'];
    >>> $suburb = $_POST['suburb'];
    >>> $city = $_POST['city'];
    >>> $postcode = $_POST['postcode'];
    >>> $gender = $_POST['gender'];
    >>> $country = $_POST['country'];
    >>>
    >>> if (empty($username)) {
    >>> $error1 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter a username</td></tr>";
    >>> }
    >>> if (empty($email)) {
    >>> $error1 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter a email address</td></tr>";
    >>> }else if(!preg_match($emailPattern,$email)) {
    >>> $error1 .= "<tr align=\"center\"><td class=\"error\">Invalid email
    >>> address</td></tr>";
    >>> }
    >>> if (empty($password)) {
    >>> $error1 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter a password</td></tr>";
    >>> }
    >>> if (empty($confpassword)) {
    >>> $error1 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter a confirm password</td></tr>";
    >>> }
    >>> if(isset($password) && isset($confpassword)) {
    >>> if($password != $confpassword) {
    >>> $error1 .= "<tr align=\"center\"><td class=\"error\">Confirm
    >>> Password must match Password feild</td></tr>";
    >>> $password = "";
    >>> $confpassword = "";
    >>> }
    >>> }
    >>> if (empty($firstname)) {
    >>> $error2 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter your first name</td></tr>";
    >>> }
    >>> if (empty($lastname)) {
    >>> $error2 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter your last name</td></tr>";
    >>> }
    >>> if (empty($address)) {
    >>> $error3 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter your email address</td></tr>";
    >>> }
    >>> if (empty($suburb)) {
    >>> $error3 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter your suburb</td></tr>";
    >>> }
    >>> if (empty($city)) {
    >>> $error3 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter your city</td></tr>";
    >>> }
    >>> if (empty($country)) {
    >>> $error3 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter your country</td></tr>";
    >>> }
    >>>
    >>> if(isset($error1)) {
    >>> echo "<table width=\"300\" border=\"1\" align=\"center\"
    >>> bordercolor=\"#000000\">" . $error1 . "</table>";
    >>> }
    >>>
    >>> if (empty($error1) && empty($error2) && empty($error3)) {
    >>> $sql = "SELECT user_name " .
    >>> "FROM members " .
    >>> "WHERE user_name = '$username'";
    >>> $result = mysql_query($sql)
    >>> or die(mysql_error());
    >>>
    >>> if(mysql_num_rows($result) == 0) {
    >>> $sql = "INSERT INTO members (user_name, password, email,
    >>> first_name, last_name, gender, address, suburb, city, postcode,
    >>> country) " . "VALUES ('$username', PASSWORD('$password'),
    >>> '$email', '$firstname', '$lastname', '$gender', '$address',
    >>> '$suburb', '$city', '$postcode', '$country');";
    >>> $result = mysql_query($sql)
    >>> or die(mysql_error());
    >>> header("Location:sendconf.php");
    >>> } else {
    >>> echo "<p align=\"center\" class=\"black\">Username \"" .
    >>> $username . "\" is already taken</p>";
    >>> $username = "";
    >>> }
    >>> }
    >>> }
    >>>>
    >>>
    >>> "rob::db" <rob@digitalburn.net> wrote in message
    >>> news:d8o1iq$kcl$1@forums.macromedia.com...
    >>>> This is a common problem. The headers have to be sent *before*
    >>>> everything else -- if you've sent any HTML at all, even just a line
    >>>> break or a bit of white space somewhere, the headers won't send. So
    >>>> just make sure the headers
    >>>> get sent by a PHP block that appears before the opening HTML tag.
    >>>>
    >>>> Location is the best redirection header to use...
    >>>>
    >>>>
    >>>> ....hooligan wrote:
    >>>>> Hey again, im trying to redirect the user to another page after a
    >>>>> succesful INSERT into a database,
    >>>>> by using the header(); function and i get the following message
    >>>>>
    >>>>> Warning: Cannot modify header information - headers already sent by
    >>>>> (output started at c:\htdocs\site_test\register.php:59) in
    >>>>> c:\htdocs\site_test\register.php on line 74
    >>>>>
    >>>>> Its a self processing form. I made it like that so users wont have
    >>>>> to go back and forth between pages to enter information could that
    >>>>> be causing the problem?
    >>>>> What should i use to redirect the users to the success.php page
    >>>>>
    >>>>> i originally tried
    >>>>>
    >>>>> header("Refresh: 2; URL=success.php");
    >>>>> header("Location: success.php");
    >>>>>
    >>>>> but both got the same problem
    >>>>>
    >>>>> Thanks in advance
    >>
    >>
    >
    >

    ....hooligan Guest

  8. #7

    Default Re: [PHP] Header problem

    Its all good just worked out how to fix it. Thanks for the help again.

    "....hooligan" <robochippy@aapt.net.au> wrote in message
    news:d8p234$343$1@forums.macromedia.com...
    > Nope no white space? Anything else it could be?
    >
    > "rob::db" <rob@digitalburn.net> wrote in message
    > news:d8o4a2$nem$1@forums.macromedia.com...
    >> Have you got a space in the file before the first PHP tag opens?
    >>
    >>
    >> ....hooligan wrote:
    >>> The header is in the php tags before the <html> tags and it still
    >>> happens. Is it something im setting in the top php tags that stuffs
    >>> me up
    >>> Heres what in the opening php tags. The header appears down the
    >>> bottom of it
    >>>
    >>> <?php
    >>> include "inc.conn.php";
    >>> if(isset($_POST['submit']) && $_POST['submit'] == "Submit") {
    >>> $emailPattern = '/^\w[-.\w]*@([-a-z0-9]+\.)+[a-z]{2,4}$/i';
    >>> $error1 = "";
    >>> $error2 = "";
    >>> $error3 = "";
    >>> $username = $_POST['username'];
    >>> $email = $_POST['email'];
    >>> $password = $_POST['password'];
    >>> $confpassword = $_POST['confpassword'];
    >>> $firstname = $_POST['firstname'];
    >>> $lastname = $_POST['lastname'];
    >>> $address = $_POST['address'];
    >>> $suburb = $_POST['suburb'];
    >>> $city = $_POST['city'];
    >>> $postcode = $_POST['postcode'];
    >>> $gender = $_POST['gender'];
    >>> $country = $_POST['country'];
    >>>
    >>> if (empty($username)) {
    >>> $error1 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter a username</td></tr>";
    >>> }
    >>> if (empty($email)) {
    >>> $error1 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter a email address</td></tr>";
    >>> }else if(!preg_match($emailPattern,$email)) {
    >>> $error1 .= "<tr align=\"center\"><td class=\"error\">Invalid email
    >>> address</td></tr>";
    >>> }
    >>> if (empty($password)) {
    >>> $error1 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter a password</td></tr>";
    >>> }
    >>> if (empty($confpassword)) {
    >>> $error1 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter a confirm password</td></tr>";
    >>> }
    >>> if(isset($password) && isset($confpassword)) {
    >>> if($password != $confpassword) {
    >>> $error1 .= "<tr align=\"center\"><td class=\"error\">Confirm
    >>> Password must match Password feild</td></tr>";
    >>> $password = "";
    >>> $confpassword = "";
    >>> }
    >>> }
    >>> if (empty($firstname)) {
    >>> $error2 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter your first name</td></tr>";
    >>> }
    >>> if (empty($lastname)) {
    >>> $error2 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter your last name</td></tr>";
    >>> }
    >>> if (empty($address)) {
    >>> $error3 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter your email address</td></tr>";
    >>> }
    >>> if (empty($suburb)) {
    >>> $error3 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter your suburb</td></tr>";
    >>> }
    >>> if (empty($city)) {
    >>> $error3 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter your city</td></tr>";
    >>> }
    >>> if (empty($country)) {
    >>> $error3 .= "<tr align=\"center\"><td class=\"error\">You must
    >>> enter your country</td></tr>";
    >>> }
    >>>
    >>> if(isset($error1)) {
    >>> echo "<table width=\"300\" border=\"1\" align=\"center\"
    >>> bordercolor=\"#000000\">" . $error1 . "</table>";
    >>> }
    >>>
    >>> if (empty($error1) && empty($error2) && empty($error3)) {
    >>> $sql = "SELECT user_name " .
    >>> "FROM members " .
    >>> "WHERE user_name = '$username'";
    >>> $result = mysql_query($sql)
    >>> or die(mysql_error());
    >>>
    >>> if(mysql_num_rows($result) == 0) {
    >>> $sql = "INSERT INTO members (user_name, password, email,
    >>> first_name, last_name, gender, address, suburb, city, postcode,
    >>> country) " . "VALUES ('$username', PASSWORD('$password'),
    >>> '$email', '$firstname', '$lastname', '$gender', '$address',
    >>> '$suburb', '$city', '$postcode', '$country');";
    >>> $result = mysql_query($sql)
    >>> or die(mysql_error());
    >>> header("Location:sendconf.php");
    >>> } else {
    >>> echo "<p align=\"center\" class=\"black\">Username \"" .
    >>> $username . "\" is already taken</p>";
    >>> $username = "";
    >>> }
    >>> }
    >>> }
    >>>>
    >>>
    >>> "rob::db" <rob@digitalburn.net> wrote in message
    >>> news:d8o1iq$kcl$1@forums.macromedia.com...
    >>>> This is a common problem. The headers have to be sent *before*
    >>>> everything else -- if you've sent any HTML at all, even just a line
    >>>> break or a bit of white space somewhere, the headers won't send. So
    >>>> just make sure the headers
    >>>> get sent by a PHP block that appears before the opening HTML tag.
    >>>>
    >>>> Location is the best redirection header to use...
    >>>>
    >>>>
    >>>> ....hooligan wrote:
    >>>>> Hey again, im trying to redirect the user to another page after a
    >>>>> succesful INSERT into a database,
    >>>>> by using the header(); function and i get the following message
    >>>>>
    >>>>> Warning: Cannot modify header information - headers already sent by
    >>>>> (output started at c:\htdocs\site_test\register.php:59) in
    >>>>> c:\htdocs\site_test\register.php on line 74
    >>>>>
    >>>>> Its a self processing form. I made it like that so users wont have
    >>>>> to go back and forth between pages to enter information could that
    >>>>> be causing the problem?
    >>>>> What should i use to redirect the users to the success.php page
    >>>>>
    >>>>> i originally tried
    >>>>>
    >>>>> header("Refresh: 2; URL=success.php");
    >>>>> header("Location: success.php");
    >>>>>
    >>>>> but both got the same problem
    >>>>>
    >>>>> Thanks in advance
    >>
    >>
    >
    >

    ....hooligan Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139