redirect (php newbie)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dribbles9903
Forum Newbie
Posts: 4
Joined: Tue Jul 23, 2002 3:17 pm

redirect (php newbie)

Post 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
User avatar
haagen
Forum Commoner
Posts: 79
Joined: Thu Jul 11, 2002 3:57 pm
Location: Sweden, Lund

Post 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.
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

Blast. Beat to the punch. :D
dribbles9903
Forum Newbie
Posts: 4
Joined: Tue Jul 23, 2002 3:17 pm

Post by dribbles9903 »

thanks, i'll try it out.
dribbles9903
Forum Newbie
Posts: 4
Joined: Tue Jul 23, 2002 3:17 pm

error message

Post 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>
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post 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 .
dribbles9903
Forum Newbie
Posts: 4
Joined: Tue Jul 23, 2002 3:17 pm

Post by dribbles9903 »

thanks for the help and the tips!
Post Reply