• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

How to implement page redirection in php/html page

Hi,

I had a very simple html page that allowed our management to select a date for a specific report they wanted to view. BTW, for the date selection, I am using the Future Shock Date Selector - free version. Any way, the simple page worked well. Now another requirement has been added - the ability to select which report they want to view and the date. I used a drop down for the report selection rather than radio buttons as the number of selections is going to grow.

I wasn't sure how I could have a form process itself, but upon reading it looks like it might work. I have been trying a number of different ways to incorporate the php code with the html to do this, but have had no luck yet. I have pasted my latest iteration below, and would be very appreciative if someone could help me to get this to work.

Thanks,
Jeff

<?php
$reportname = $_POST["rptname"];
$reportdate = $_POST["rptdate"];
$val = strcmp($reportname, "Select a report");
if ($val != 0)
{
      if (strcmp($reportname,"sac-ebiz-int") == 0)
      {
            header("Location: topservices_int.php?rptdate=rptdate.text");
      }
      else
      {
            header("Location: topservices_idmz.php?rptdate=rptdate.text");
      }
}
?>
<HTML>
<HEAD><TITLE>Report Selctor</TITLE>
<SCRIPT LANGUAGE="JavaScript" SRC="scripts/FSdateSelect.js"></SCRIPT>
<LINK REL="stylesheet" HREF="styles/FSdateSelect.css" type="text/css"></LINK>
</HEAD>
      <BODY>
            <TABLE border="0" width="50%"  align="center">
                  <TR><TH valign="bottom"><H2 align="center">Firewall Report Viewer</H2></TH><TH align="right"><IMG src="../images/vz3.gif"></TH></TR>
            </TABLE>            
            <HR align="center" color="red" width="600px">
            <BR>&nbsp<BR>
            <TABLE border="0" width="50%" align="center">
                  <TR><TD align="center">
                        <FORM method="POST" action="<?php echo $_SERVER[PHP_SELF]; ?>" name="dateform" align="center"></tr>
                        <tr><TD align="left" width="30%">Select report</TD>
                        <TD><select name="rptname">
                        <option>Select a report</option>
                        <option value="sac-ebiz-int">sac-ebiz-int</option>
                        <option value="sac-ebiz-idmz">sac-ebiz-idmz</option></tr>
                        <TR><TD>&nbsp</TD></TR>
                        <tr><TD align="left" width="30%">Select date for report: </TD>
                        <TD align="left"><SCRIPT LANGUAGE="JavaScript">FSfncWriteFieldHTML("dateform","rptdate","04/25/2006",100,"images/FSdateSelector/","US",false,true)</SCRIPT></TD>
                        <TD align="left"><INPUT TYPE=submit Value="Get report"></TD>
                        </FORM>
                  </TD></TR>
            </TABLE>
            <TABLE border="0" width="50%" align="center">
                  <TR><TD>&nbsp</TD></TR>
                  <TR><TD>&nbsp</TD></TR>
                  <TR><TD>&nbsp</TD></TR>
                  <TR><TD>&nbsp</TD></TR>
                  <TR><TD>&nbsp</TD></TR>
                  <TR><TD>&nbsp</TD></TR>
                  <TR><TD>&nbsp</TD></TR>
                  <TR><TD>&nbsp</TD></TR>
                  <TR><TD>&nbsp</TD></TR>
                  <TR><TD>&nbsp</TD></TR>
                  <TR><TD>&nbsp</TD></TR>
                  <TR><TD>&nbsp</TD></TR>
                  <TR><TH align="center"><IMG src="../images/apache_pb.gif" width="130px"></TH></TR>
            </TABLE>
      </BODY>
</HTML>
0
jpetter
Asked:
jpetter
  • 2
  • 2
1 Solution
 
m1tk4Commented:
a) you can compare string variables directly (i.e. if ($reportname == "Select a report") {}) instead of using strcmp(). (just a note)
b) strictly speaking, after header("Location: ") call you need to exit() right away since all output will be ignored anyway.
c) you can just leave action attribute empty, it will post to self.
d) try doing a

print_r($_POST) to troubleshoot what kind of values you get in PHP after a POST request.
0
 
LinuxNubbCommented:
Also, if you are going to use the header redirection, it's a good idea to use php's output buffering (ob_start/ob_end_flush).  This will prevent any "headers already sent" error messages from appearing on your page:

<?php
obstart();
$reportname = $_POST["rptname"];
$reportdate = $_POST["rptdate"];
$val = strcmp($reportname, "Select a report");
if ($val != 0)
{
     if (strcmp($reportname,"sac-ebiz-int") == 0)
     {
          header("Location: topservices_int.php?rptdate=rptdate.text");
     }
     else
     {
          header("Location: topservices_idmz.php?rptdate=rptdate.text");
     }
}

ob_end_flush();
?>
0
 
jpetterAuthor Commented:
I made all the suggested changes, and it now works....I think the problem was in the action attribute.

Thanks,
Jeff
0
 
jpetterAuthor Commented:
LinuxNubb,

Thanks for the tip...sorry I didn't see your post until I had already closed this out.

Thanks,
Jeff
0
 
LinuxNubbCommented:
That's ok, just trying to make the world a better place! :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now