Page 1 of 1

redirect (php newbie)

Posted: Tue Jul 23, 2002 3:17 pm
by dribbles9903
I have a page that submits a form, and then I need it to redirect back to a previous page. What commands will I need for this?
Thanks

Posted: Tue Jul 23, 2002 3:20 pm
by haagen
Try:

Code: Select all

Header("Location: otherpage.php");
You cannot print anyting before this command to the client. So the first thing your script i sending the client is the Location header. Otherwise you'll get an error.

Posted: Tue Jul 23, 2002 3:21 pm
by RandomEngy
Blast. Beat to the punch. :D

Posted: Tue Jul 23, 2002 3:35 pm
by dribbles9903
thanks, i'll try it out.

error message

Posted: Tue Jul 23, 2002 3:43 pm
by dribbles9903
k, that didn't work so I'm gonna give some more info as to what I've got.

input page = enter info into form, click to view your info

print1 = view your info, decide to either submit or go back

print2 = if submitted, print2 takes values sent from print1 and 'mail' s them. print2 is the page that i need redirected

here is the code for print2

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>EAHR: Send Student Form PHP</title>
</head>

<body>

<br><br>
<?php

Header("Location: student.php");

$send = "eahradvisor@coe.tamu.edu";
$subject = "Student Employment";
$body = "Fullname: $fullname \n";
$body.= "Date: $date \n";
$body.= "Social Security Number: $SSN \n";
$body.= "Email: $email \n";
$body.= "Home Address: $address \n";
$body.= "Phone Number: $phone \n";
$body.= "Fax Number: $fax \n";
$body.= "Primary skills: 1. $skill1 \n";
$body.= "2. $skill2 \n";
$body.= "3. $skill3 \n";
$body.= "4. $skill4 \n";
$body.= "5. $skill5 \n";
$body.= "Career Objectives: $objectives \n";
$body.= "Academic Department: $dept \n";
$body.= "Departmental Admission Date: $admdate \n";
$body.= "Degree Program: $degree \n";
$body.= "Semester: $semester \n";
$body.= "Year: $year \n";
$fromemail = $email;


mail( $send ,$subject , $body , $fromemail);





?>
</body>
</html>

Posted: Tue Jul 23, 2002 4:04 pm
by RandomEngy
Remember, you must do the header before you output any information to the page. Change it to something like this:

Code: Select all

<?php

$send = "eahradvisor@coe.tamu.edu"; 
$subject = "Student Employment"; 
$body = "Fullname: $fullname \n"; 
...
$body.= "Year: $year \n"; 
$fromemail = $email; 

mail( $send ,$subject , $body , $fromemail);

Header("Location: student.php");

?>
It's important not to have any HTML before you do your header().

Also, try getting in the habit of using $_POST['fieldname'] or $_GET['fieldname'] instead of just $fieldname .

Posted: Tue Jul 23, 2002 5:08 pm
by dribbles9903
thanks for the help and the tips!