Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another Redirection question

Status
Not open for further replies.

AlanArons

Programmer
Aug 1, 2002
91
US
It should be simple, but I am stumped.

I have a series of pages at a website that allows a user to apply for a postion. A .php script uses an include() routine to load data from a MySQL table into the first page of the series.

After the page is edited, I want to save the data back to the table, so I define my form
<form method="post" action="#process">
where #process is a tag in the html portion of the script

I use another include() routine to save the data back to the table. Everything works to this point.

How do I now send the system to the next page in the sequence. Using the Header(Location) generates an error.

Alan Arons[ponder]
 
I've used simple javascript in the past.
Code:
<body onload=setTimeout("location.href=''",2500)>
the 2500 is time in milliseconds.
Just use a php varible and check in the post settings after the page has been submitted to autodirect to the next page
 
When I do that, the script immediately goes to the next page without stopping for input.

I suspect that I dont want to use the Header command in this case but dont really know how to handle it

Alan Arons[ponder]
 
You'll want to use an if statement to see when you want to redirect. Set a hidden text field among your other fields with a value of say '1' call it "Submitted". Then when you page gets submitted read the post varible for "Submitted". Then you can use an if statement to check the value of "Submitted" and if true then send the header info. else do nothing. There may be a way to just simply check the post array as a whole maybe?
Code:
if(isset($_POST[])
  header();
else
  //do nothing;
Just my idea. Kind of a "hack
 
what you should be doing is handling the input before you deal with the header. your relevant php should occur before your call to the header. example:

Code:
<?

include("file.php");

if ( isset( $_POST['myField'] ) ) {
    $sql = "insert into table(col1) values ('" . $_POST['myField'] . "'";
    if ( doInsert( $sql ) ) {
        header("Location: result_page.php");
    } else {
        $error = "Could not add record to database.";
    }
} else {
    $error = "Please fill out the field labeled 'myField'";
}

?>

<html>
  ....
</html>



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top