SitePoint Sponsor

User Tag List

Results 1 to 25 of 25
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can anyoane please help me?

    I get an error which is driving me mad.
    I am trying to redirect to thankyou page from a contact form .
    The details will be stored in my database but instead redirection I receive:

    Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\test\dabisolutions\site\contact_us.php:14) in C:\Program Files\Apache Group\Apache2\test\dabisolutions\site\contact_form1.php on line 55

    my code for redirection is:

    $insertGoTo = "thankyou.html";
    if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
    }
    header(sprintf("Location: %s",$insertGoTo));

    on the 14 line in contact_us.php I've got:
    <img id="logo1" src="slices/logo.gif" alt="Dabi Solutions - Online Marketing"> AND

    on the line 55 on the contact_form1 I've got:
    header(sprintf("Location: %s",$insertGoTo));

    The contact_form1.php is included in contact_us.php

    Please anyone can help me?
    Thank you.

  2. #2
    SitePoint Guru dbevfat's Avatar
    Join Date
    Dec 2004
    Location
    ljubljana, slovenia
    Posts
    684
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, the error message is quite useful here - it tells you that you cannot post headers, because something else was already posted.

    The header you're trying to send (Location: ...) is a HTTP header and as such must be the first thing to be output by your script. Obviously, this is not the case, since you're already outputing some html before.

    You could move that header code before that html, this would be the easy way.

  3. #3
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dbevfat
    Well, the error message is quite useful here - it tells you that you cannot post headers, because something else was already posted.

    The header you're trying to send (Location: ...) is a HTTP header and as such must be the first thing to be output by your script. Obviously, this is not the case, since you're already outputing some html before.

    You could move that header code before that html, this would be the easy way.
    Or you can add ob_start() as the first line in the script and use PHP's output buffering to avoid having to move the header code. This also takes care of any other header errors. Also add exit() after the header declarations. HTH
    Erh

  4. #4
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is all my php script from contact_form1 followed (not-posted) by the usual html code with the input tags for my contact form.
    I don't have any html wich is sendind the page to thankyou.html.
    Can you plase have a look and tell me where I've made a mistake?
    Thank you again.


    <?php
    require_once('../Connections/contactform1.php');
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }

    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
    $insertSQL = sprintf("INSERT INTO clients_for_newsletter (first_name, second_name, company, email, web, tel, mobile, fax, Address, city, country, enquiries, checkbox) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
    GetSQLValueString($_POST['first_name'], "text"),
    GetSQLValueString($_POST['second_name'], "text"),
    GetSQLValueString($_POST['company'], "text"),
    GetSQLValueString($_POST['email'], "text"),
    GetSQLValueString($_POST['web'], "text"),
    GetSQLValueString($_POST['tel'], "int"),
    GetSQLValueString($_POST['mobile'], "int"),
    GetSQLValueString($_POST['fax'], "int"),
    GetSQLValueString($_POST['Address'], "text"),
    GetSQLValueString($_POST['city'], "text"),
    GetSQLValueString($_POST['country'], "text"),
    GetSQLValueString($_POST['enquiries'], "text"),
    GetSQLValueString(isset($_POST['checkbox']) ? "true" : "", "defined","'Y'","'N'"));
    mysql_select_db($database_contactform1, $contactform1);
    $Result1 = mysql_query($insertSQL, $contactform1) or die(mysql_error());
    }
    $insertGoTo = "thankyou.html";
    if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
    }
    header(sprintf("Location: %s",$insertGoTo));
    ?>

  5. #5
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    See my above post.
    Erh

  6. #6
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've got this error now:
    Parse error: parse error, unexpected T_REQUIRE_ONCE in C:\Program Files\Apache Group\Apache2\test\dabisolutions\site\contact_form1.php on line 2

    The require file is my config. file to connect to the database, apache.........

    And I cannot see my contact form no more.

  7. #7
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by catalin
    I've got this error now:
    Parse error: parse error, unexpected T_REQUIRE_ONCE in C:\Program Files\Apache Group\Apache2\test\dabisolutions\site\contact_form1.php on line 2

    The require file is my config. file to connect to the database, apache.........

    And I cannot see my contact form no more.
    What does your script look like now. Remember that the [ php ] tags are nice for situations like displaying your code for us.
    Erh

  8. #8
    SitePoint Guru dbevfat's Avatar
    Join Date
    Dec 2004
    Location
    ljubljana, slovenia
    Posts
    684
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a completely different problem. The first one that you described was caused by the html code in line 14 of file contact_us.php, so you actually _did_ have some html code output before the headers.

    In this code you posted, you're including a file called contactform1.php, which probably has some html code in it? That html is sent to the browser before your header() call is made. Mandibal and I told you how to solve this.

    About this last error, not sure what causes it, it looks like some syntax error, but I cannot say more until I see your code. The one posted in your previous post looks ok, did you change anything?

    Regards

  9. #9
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My script is looking like that now:
    I hope the script is undestandable

    <?php ob_start()
    require_once ("../contactform1.php");
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }

    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
    $insertSQL = sprintf("INSERT INTO clients_for_newsletter (first_name, second_name, company, email, web, tel, mobile, fax, Address, city, country, enquiries, checkbox) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
    GetSQLValueString($_POST['first_name'], "text"),
    GetSQLValueString($_POST['second_name'], "text"),
    GetSQLValueString($_POST['company'], "text"),
    GetSQLValueString($_POST['email'], "text"),
    GetSQLValueString($_POST['web'], "text"),
    GetSQLValueString($_POST['tel'], "int"),
    GetSQLValueString($_POST['mobile'], "int"),
    GetSQLValueString($_POST['fax'], "int"),
    GetSQLValueString($_POST['Address'], "text"),
    GetSQLValueString($_POST['city'], "text"),
    GetSQLValueString($_POST['country'], "text"),
    GetSQLValueString($_POST['enquiries'], "text"),
    GetSQLValueString(isset($_POST['checkbox']) ? "true" : "", "defined","'Y'","'N'"));
    mysql_select_db($database_contactform1, $contactform1);
    $Result1 = mysql_query($insertSQL, $contactform1) or die(mysql_error());
    }
    $insertGoTo = "thankyou.html";
    if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
    }
    header(sprintf("Location: %s",$insertGoTo));
    exit()
    ?>

  10. #10
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Most likely the problem is that ob_start(); needs to be on a line by itself like this:
    PHP Code:
    <?php
    ob_start
    ();
    require_once (
    "../contactform1.php");
    ...
    Erh

  11. #11
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've got the error on line3 now

    Parse error: parse error, unexpected T_REQUIRE_ONCE in C:\Program Files\Apache Group\Apache2\test\dabisolutions\site\contact_form1.php on line 3

  12. #12
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by catalin
    I've got the error on line3 now

    Parse error: parse error, unexpected T_REQUIRE_ONCE in C:\Program Files\Apache Group\Apache2\test\dabisolutions\site\contact_form1.php on line 3
    In the example you posted there is no semi-colon after ob_start(). Is this still the case in your script?
    Erh

  13. #13
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've put the semicolon after ob_start [ ex: ob_start () { ] and I've close it
    before exit() and I have the following error now
    Parse error: parse error, unexpected '{' in C:\Program Files\Apache Group\Apache2\test\dabisolutions\site\contact_form1.php on line 2.

    There is any other way to redirect my contact form after submitting to my thank you page?

  14. #14
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by catalin
    I've put the semicolon after ob_start [ ex: ob_start () { ] and I've close it
    before exit() and I have the following error now
    Parse error: parse error, unexpected '{' in C:\Program Files\Apache Group\Apache2\test\dabisolutions\site\contact_form1.php on line 2.

    There is any other way to redirect my contact form after submitting to my thank you page?
    As dbevfat mentioned these errors are syntax errors. Missing semi-colons or { or } etc. Trying to find different solutions because your getting syntax errors is not very productive. Check around line 2 in contact_form1.php for syntax errors.
    Last edited by Mandibal; Apr 28, 2005 at 06:38. Reason: Read spikz post and realized that I misread the error and what catalin said.
    Erh

  15. #15
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    Semi colon is ;
    brace is {
    PHP Code:
    <?php 
    ob_start
    ();
    require_once (
    "../contactform1.php"); 
    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

    switch (
    $theType) {
    case 
    "text":
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
    break; 
    case 
    "long":
    case 
    "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case 
    "double":
    $theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
    break;
    case 
    "date":
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
    break;
    case 
    "defined":
    $theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
    break;
    }
    return 
    $theValue;
    }

    $editFormAction $_SERVER['PHP_SELF'];
    if (isset(
    $_SERVER['QUERY_STRING'])) {
    $editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
    }
    if ((isset(
    $_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
    $insertSQL sprintf("INSERT INTO clients_for_newsletter (first_name, second_name, company, email, web, tel, mobile, fax, Address, city, country, enquiries, checkbox) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
    GetSQLValueString($_POST['first_name'], "text"),
    GetSQLValueString($_POST['second_name'], "text"),
    GetSQLValueString($_POST['company'], "text"),
    GetSQLValueString($_POST['email'], "text"),
    GetSQLValueString($_POST['web'], "text"),
    GetSQLValueString($_POST['tel'], "int"),
    GetSQLValueString($_POST['mobile'], "int"),
    GetSQLValueString($_POST['fax'], "int"),
    GetSQLValueString($_POST['Address'], "text"),
    GetSQLValueString($_POST['city'], "text"),
    GetSQLValueString($_POST['country'], "text"),
    GetSQLValueString($_POST['enquiries'], "text"),
    GetSQLValueString(isset($_POST['checkbox']) ? "true" """defined","'Y'","'N'"));
    mysql_select_db($database_contactform1$contactform1);
    $Result1 mysql_query($insertSQL$contactform1) or die(mysql_error());
    }
    $insertGoTo "thankyou.html";
    if (isset(
    $_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
    }
    header(sprintf("Location: %s",$insertGoTo));
    exit()
    ?>
    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  16. #16
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am sorry SpikeZ.
    I have to improve my english.
    I've tryed now with the semicolon aswell but still no change.

    Mandibal I've checked my contact_form1.
    The file is all the php script which I've posted above plus some html.

  17. #17
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    If the code above is contact_form1.php, why are you using a require() if the contents of contact_form1.php include your mysql_pconnect() then fine, use require but there really shouldn't be much else in it.

    (you can't include the file you are using in the the file you are using!!!)

    Cheers

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  18. #18
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is my required file

    <?php
    $hostname_contactform1 = "localhost";
    $database_contactform1 = "contact";
    $username_contactform1 = "username";
    $password_contactform1 = "password";
    $contactform1 = mysql_pconnect($hostname_contactform1, $username_contactform1, $password_contactform1) or trigger_error(mysql_error(),E_USER_ERROR);
    ?>

  19. #19
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    I was looking back to your first post....
    Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\test\dabisolutions\site\contact_us.php:14) in C:\Program Files\Apache Group\Apache2\test\dabisolutions\site\contact_form1.php on line 55
    When something suddenly occurred to me.....
    There is nothing wrong with the code you posted in post#9, the problem is on contact_us.php line 14. Could you be a darling and post the contact us page code!

    Cheers

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  20. #20
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is my contact_us page.
    I think I've seen the problem.
    I've highlighted the php code in this file and I dont think is in the right position but if I'm going to change that all in my page will be messed up.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Dabi Solutions - Contact us</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="styleservices.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <div id="main">


    <div id="logo">
    <img id="logo1" src="slices/logo.gif" alt="Dabi Solutions - Online Marketing">
    </div>
    <div id="topnav">
    <ul>
    <li id="home"><a href="index.html">about us</a></li>
    <li id="services"><a href="services.html">services</a></li>
    <li id="clients"><a href="clients.html">clients</a></li>
    <li id="contact"><a href="contact_us.php">contact us</a></li>
    <li id="sitemap"><a href="../forum/index.php">forum</a></li>
    </ul>
    </div>

    <div id="title1">
    <p id="p1">Links to our site</p>
    </div>

    <div id="title2">
    <h1>Contact Us</h1>
    </div>

    <div id="rightnav">
    <ul>
    <li id="seo"><a href="index.html">about us</a></li>
    <li id="ppc"><a href="location.html">location</a></li>
    </ul>
    </div>

    <div id="text">
    <?php include "contact_form1.php"?>
    </div>
    <div id="footer">
    <img id="roflag" src="images/ro.png" alt="Romanian Version">
    <ul>
    <li><a href="index.html">about us</a></li>
    <li><a href="privacy_policy.html">privacy policy</a></li>
    <li><a href="site_map.html">site map</a></li>
    <li><a href="../forum/index.php">forum</a></li>
    </ul>
    </div>

    <div id="copyright">
    <p id="pc">
    Copyright &copy; 2005. All rights reserved.<br>
    No part of this website may be reproduced in any form
    without the express written consent of Dabi Solutions.
    </p>
    </div>


    </div>
    </boby>
    </html>

  21. #21
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    AAAAAAAAAAAAAAAAAAAAAALRIGHTY THEN, now we are cookin'.

    The problem as you rightly say is that the form is being included way down the page.
    Here's what you can do....

    1./ on your page with the form, cut the form out of the coding leaving all the php above alone,
    2./ paste the form into the above contact_us page. so now you have the form on the page and change the form action to contact_form1.php (the page with the code still on it)
    3./ sit back and relax!

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  22. #22
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've changed the position of the included file and it's redirect me straight away but I don't have the chance to fill the contact form .

    So when i hit the contact tab I will see the thank you page instead the form

  23. #23
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well well well my big mystery has been solved.
    Thank you very much

  24. #24
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    woooooooooooooooo hoooooooooooooooooo strike on for the fat boy!

    Glad you got it sorted catalin!


    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  25. #25
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks again
    You're the man.


Bookmarks

Posting Permissions

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