redirect a print statement off a page so it doesn't conflict with aheader

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JRough

    redirect a print statement off a page so it doesn't conflict with aheader

    I have this code that switches templates depending on if the user
    fills in a form with a request. The request asks for the $mark &
    $number. If that request gets input then it displays a list otherwise
    it re-displays the form request. The $template variable changes the
    value of which template is displayed.
    if($mark&&$num) {
    $mark = $mark = strtoupper($mar k);
    $TPL_carnumbers = GetHeaders($_SE SSION["LMS_USER_D ESC"]);

    $xclheader =
    array('CLM_id', 'TRIP_id','Car_ number','Sighti ng_Date','Code' ,'Location','', 'Location_Splc' ,
    'L_E','railroad ','Destination' ,
    '','Destination _Splc','Car_num ber','',
    'Classification ','Origin', '','ETA');
    $xclfields =
    array('clm_id', 'trip_id','car_ mark','car_numb er','sighting_d ate','sighting_ code',
    'location_city' ,'location_stat e','location_sp lc','l_e','rail road','destinat ion_city',
    'destination_st ate','destinati on_splc',
    'car_mark','car _number','class ification','ori gin_city',
    'origin_state',
    'eta');


    # GET CARS FOR GIVEN ID AND TYPE?
    $result = SELECT_clm($mar k,$num);

    if(mysql_numrow s($result)==0){
    $TPL_error_valu e = "No Data for this Carnumber - Please Enter
    Another Mark and Number";
    $template = "clm_history_ph p.html";
    }else{
    while ($row = mysql_fetch_ass oc($result)){
    $TPL_carnumbers .=MakeSighting( $_SESSION["LMS_USER_D ESC"],$row);
    }
    }
    $MSG_carlist = "SIGHTING HISTORY FOR ".MakeCarnumber ($mark,$num);
    $TPL_carnumbers .="</table>";
    $template = "template_carli st.html";

    if ($_POST['assign']!='Open in Excel'){
    include "header.php ";
    include "footer.php ";

    }else{
    $file_name = str_replace('.p hp?','',$file_n ame);
    printxcl($data, $header,$file_n ame){
    }
    }else{
    $template = "clm_history_ph p.html";
    }

    include "header.php ";
    include $template_path. "$template" ;
    include "footer.php ";

    I have an error in this page on the printxcl() function because there
    is the earlier call to include the header.php page, On line 39 of
    header.php page is
    this line:
    header( 'Content-type: text/html; charset=\"$CHAR SET\"' );
    which conflicts with the print statement in the printxcl() function.

    How can I redirect that function /print statement to another page so I
    don't get that error:

    Warning: Cannot modify header information - headers already sent by
    (output started at /home/allrail/public_html/templates/header.php.html :
    15) in /home/allrail/public_html/header.php on line 39

    Even though I tried moving the print statement to the function it
    still hits on the page and I still get the error.

    thanks very much,
  • Jerry Stuckle

    #2
    Re: redirect a print statement off a page so it doesn't conflictwith a header

    JRough wrote:
    I have this code that switches templates depending on if the user
    fills in a form with a request. The request asks for the $mark &
    $number. If that request gets input then it displays a list otherwise
    it re-displays the form request. The $template variable changes the
    value of which template is displayed.
    if($mark&&$num) {
    $mark = $mark = strtoupper($mar k);
    $TPL_carnumbers = GetHeaders($_SE SSION["LMS_USER_D ESC"]);
    >
    $xclheader =
    array('CLM_id', 'TRIP_id','Car_ number','Sighti ng_Date','Code' ,'Location','', 'Location_Splc' ,
    'L_E','railroad ','Destination' ,
    '','Destination _Splc','Car_num ber','',
    'Classification ','Origin', '','ETA');
    $xclfields =
    array('clm_id', 'trip_id','car_ mark','car_numb er','sighting_d ate','sighting_ code',
    'location_city' ,'location_stat e','location_sp lc','l_e','rail road','destinat ion_city',
    'destination_st ate','destinati on_splc',
    'car_mark','car _number','class ification','ori gin_city',
    'origin_state',
    'eta');
    >
    >
    # GET CARS FOR GIVEN ID AND TYPE?
    $result = SELECT_clm($mar k,$num);
    >
    if(mysql_numrow s($result)==0){
    $TPL_error_valu e = "No Data for this Carnumber - Please Enter
    Another Mark and Number";
    $template = "clm_history_ph p.html";
    }else{
    while ($row = mysql_fetch_ass oc($result)){
    $TPL_carnumbers .=MakeSighting( $_SESSION["LMS_USER_D ESC"],$row);
    }
    }
    $MSG_carlist = "SIGHTING HISTORY FOR ".MakeCarnumber ($mark,$num);
    $TPL_carnumbers .="</table>";
    $template = "template_carli st.html";
    >
    if ($_POST['assign']!='Open in Excel'){
    include "header.php ";
    include "footer.php ";
    >
    }else{
    $file_name = str_replace('.p hp?','',$file_n ame);
    printxcl($data, $header,$file_n ame){
    }
    }else{
    $template = "clm_history_ph p.html";
    }
    >
    include "header.php ";
    include $template_path. "$template" ;
    include "footer.php ";
    >
    I have an error in this page on the printxcl() function because there
    is the earlier call to include the header.php page, On line 39 of
    header.php page is
    this line:
    header( 'Content-type: text/html; charset=\"$CHAR SET\"' );
    which conflicts with the print statement in the printxcl() function.
    >
    How can I redirect that function /print statement to another page so I
    don't get that error:
    >
    Warning: Cannot modify header information - headers already sent by
    (output started at /home/allrail/public_html/templates/header.php.html :
    15) in /home/allrail/public_html/header.php on line 39
    >
    Even though I tried moving the print statement to the function it
    still hits on the page and I still get the error.
    >
    thanks very much,
    >
    You can't call header() after any output has been sent to the client.
    And you can't redirect output in php to another page - the best you can
    do is buffer the output and perhaps throw it away. However, that hides
    the problem, not fixes it.

    You need to restructure your code so you don't try to call header()
    after output has been sent to the browser.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Gordon

      #3
      Re: redirect a print statement off a page so it doesn't conflict witha header

      On Sep 26, 1:59 am, JRough <jlro...@yahoo. comwrote:
      I have this code that switches templates depending on if the user
      fills in a form with a request. The request asks for the $mark &
      $number. If that request gets input then it displays a list otherwise
      it re-displays the form request.  The $template variable changes the
      value of which template is displayed.
      if($mark&&$num) {
        $mark = $mark = strtoupper($mar k);
        $TPL_carnumbers = GetHeaders($_SE SSION["LMS_USER_D ESC"]);
      >
                      $xclheader =
      array('CLM_id', 'TRIP_id','Car_ number','Sighti ng_Date','Code' ,'Location','', 'Location_Splc' ,
      'L_E','railroad ','Destination' ,
      '','Destination _Splc','Car_num ber','',
               'Classification ','Origin', '','ETA');
                      $xclfields =
      array('clm_id', 'trip_id','car_ mark','car_numb er','sighting_d ate','sighting_ code',
                              'location_city' ,'location_stat e','location_sp lc','l_e','rail road','destinat ion_city',
      'destination_st ate','destinati on_splc',
      'car_mark','car _number','class ification','ori gin_city',
      'origin_state',
                              'eta');
      >
        # GET CARS FOR GIVEN ID AND TYPE?
        $result = SELECT_clm($mar k,$num);
      >
        if(mysql_numrow s($result)==0){
          $TPL_error_valu e = "No Data for this Carnumber  -  Please Enter
      Another Mark and Number";
          $template = "clm_history_ph p.html";
        }else{
              while ($row = mysql_fetch_ass oc($result)){
            $TPL_carnumbers .=MakeSighting( $_SESSION["LMS_USER_D ESC"],$row);
              }
        }
          $MSG_carlist = "SIGHTING HISTORY FOR ".MakeCarnumber ($mark,$num);
          $TPL_carnumbers .="</table>";
              $template = "template_carli st.html";
      >
              if ($_POST['assign']!='Open in Excel'){
              include "header.php ";
              include "footer.php ";
      >
              }else{
                      $file_name = str_replace('.p hp?','',$file_n ame);
                      printxcl($data, $header,$file_n ame){
              }}else{
      >
              $template = "clm_history_ph p.html";
      >
      }
      >
      include "header.php ";
      include $template_path. "$template" ;
      include "footer.php ";
      >
      I have an error in this page on the printxcl() function because there
      is the earlier call to include the header.php page,   On line 39 of
      header.php page is
      this line:
      header( 'Content-type: text/html; charset=\"$CHAR SET\"' );
      which conflicts with the print statement in the printxcl() function.
      >
      How can I redirect that function /print statement to another page so I
      don't get that error:
      >
      Warning: Cannot modify header information - headers already sent by
      (output started at /home/allrail/public_html/templates/header.php.html :
      15) in /home/allrail/public_html/header.php on line 39
      >
      Even though I tried moving the print statement to the function it
      still hits on the page and I still get the error.
      >
      thanks very much,
      The quick and dirty workaround is to use output buffering to defer the
      sending of data to the browser until you've sent your headers.

      The correct way of doing it is to rearrange your code so it doesn't
      send any output before it's done sending headers.

      Comment

      Working...