/    Sign up×
Community /Pin to ProfileBookmark

Trying to add redirect to end of php script

Good morning all,

I am trying to add a redirect script to the end of the PHP form I created, but can’t seem to find one that will work with the PHP. Anyone have any ideas?

[URL=”http://www.jacksoncabinboys.com/jcb/fanclub.php”]Here’s a link to the file[/URL]

Here’s the PHP:

[code=php]<?php
} else {
error_reporting(0);
$recipient = ‘[email protected]’;
$subject = ‘New Fan Club Member!’;
$name = “Name:n”.stripslashes($_POST[‘name’]);
$email = “Email:n”.stripslashes($_POST[’email’]);
$cell = “Phone:n”.stripslashes($_POST[‘cell’]);
$aim = “AIM:n”.stripslashes($_POST[‘aim’]);
$add = “City:n”.stripslashes($_POST[‘aim’]);
$add2 = “State:n”.stripslashes($_POST[‘state’]);
$msg = “$namenn”.”$emailn”.”$celln”.”$aimnn”.”$addn”.”$add2n”;
if(mail(“$recipient”,”$subject”,”$msg”))
echo nl2br(“<p align=’center’>
<b>Message Sucessfully Sent!</b>
<i>Click the banner above to return to our site!</i>
</p>

);
else
echo “Message failed to send”;
}
?>[/code]

Here’s the HTML:

[code=html]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta name=”keywords” content=”jackson cabin boys, south point, ashland, huntington, country, music, matt mcclay, lance ross, jackson lake, wtcr, ohio, kentucky, west virginia, folsom prison blues, mp3, download, matt, lance, official, official site, anything but mine” />
<meta name=”description” content=”The official website of the country music duo, the Jackson Cabin Boys!” />
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>::The Official Website of the Jackson Cabin Boys::</title>
<style type=”text/css”>
<!–
body {
background-color: #333333;
}
.style2 {font-size: x-small}
.style3 {color: #CCCCCC; font-family: Arial, Helvetica, sans-serif;}
.style5 {
color: #FFFFFF;
font-family: Arial, Helvetica, sans-serif;
font-size: small;
font-weight: bold;
}
.style7 {
font-family: Arial, Helvetica, sans-serif;
font-size: small;
color: #FFFFFF;
}
a:link {
font-family: Arial, Helvetica, sans-serif;
font-size: medium;
font-style: normal;
font-weight: bold;
color: #CCCCCC;
text-decoration: none;
}
a:visited {
font-family: Arial, Helvetica, sans-serif;
font-size: medium;
font-style: normal;
font-weight: bold;
color: #CCCCCC;
text-decoration: none;
}
a:hover {
font-family: Arial, Helvetica, sans-serif;
font-size: medium;
font-style: normal;
font-weight: bold;
color: #FFFF66;
text-decoration: none;
}
–>
</style>
</head>

<body>

<?php
if ($_SERVER[‘REQUEST_METHOD’] != ‘POST’){
$me = $_SERVER[‘PHP_SELF’];
?>

<table width=”800″ border=”0″ align=”center”” cellpadding=”0″ cellspacing=”0″ bgcolor=”#000000 align=”center>
<tr>
<td bgcolor=”#666666″>
<span class=”style5″>JacksonCabinBoys.com</span></td>
</tr>
<tr>
<td bgcolor=”#999999″><div align=”center”><a href=”index.html”>Home</a> | <a href=”bio.html”>Bio</a> | <a href=”shows.html”>Shows</a> | <a href=”news.html”>News</a> | <a href=”fanclub.html”>Fan Club</a> | <a href=”media.html”>Media</a> | <a href=”contact.html”>Contact Info</a> | <a href=”http://www.myspace.com/jacksoncabinboys” target=”_new”>MySpace</a></div></td>
</tr>

<tr>
<td><img src=”images/banner_1gray.jpg” width=”800″ height=”300″ /></td>
</tr>

<tr>
<td valign=”top” bgcolor=”#000000″><table width=”795″ border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”794″ valign=”top”><pre class=”style7″> Welcome to the official website of the Jackson Cabin Boys! Whether you are a tried-and-true JCB fan, or are checking us out for the<br> first time, we hope enjoy our music. Our schedule changes often, so check our website often for the most up-to-date show times<br> and dates. Sit back, relax, and enjoy the Jackson Cabin Boys!
</pre>

<form name=”fanclubform” method=”post” action=”<?php echo $me;?>”>
<input type=”text” name=”name” id=”name” />
<span class=”style7″>Name</span>
<br />
<input type=”text” name=”email” id=”email” />
<span class=”style7″>E-Mail</span><br />
<input type=”text” name=”cell” id=”cell” size=”15″ />
<span class=”style7″>Phone</span><br />
<input type=”text” name=”aim” id=”aim” size=”20″ />
<span class=”style7″>AIM</span><br />
<input type=”text” name=”city” id=”city” />
<select name=”state” id=”state”>
<option>–</option>
<option>AL</option>
<option>AK</option>
<option>AZ</option>
<option>AR</option>
<option>CA</option>
<option>CO</option>
<option>CT</option>
<option>DE</option>
<option>DC</option>
<option>FL</option>
<option>GA</option>
<option>HI</option>
<option>ID</option>
<option>IL</option>
<option>IN</option>
<option>IA</option>
<option>KS</option>
<option>KY</option>
<option>LA</option>
<option>ME</option>
<option>MD</option>
<option>MA</option>
<option>MI</option>
<option>MN</option>
<option>MS</option>
<option>MO</option>
<option>MT</option>
<option>NV</option>
<option>NH</option>
<option>NJ</option>
<option>NM</option>
<option>NC</option>
<option>NY</option>
<option>ND</option>
<option>OH</option>
<option>OK</option>
<option>OR</option>
<option>PA</option>
<option>RI</option>
<option>SC</option>
<option>SD</option>
<option>TN</option>
<option>TX</option>
<option>UT</option>
<option>VT</option>
<option>WA</option>
<option>WV</option>
<option>WI</option>
<option>WY</option>
</select>
<span class=”style7″>City/State</span><br />
<input type=”submit” value=”Join the Club!” name=”submit” id=”submit” />
</form>

<?php
} else {
error_reporting(0);
$recipient = ‘[email protected]’;
$subject = ‘New Fan Club Member!’;
$name = “Name:n”.stripslashes($_POST[‘name’]);
$email = “Email:n”.stripslashes($_POST[’email’]);
$cell = “Phone:n”.stripslashes($_POST[‘cell’]);
$aim = “AIM:n”.stripslashes($_POST[‘aim’]);
$add = “City:n”.stripslashes($_POST[‘aim’]);
$add2 = “State:n”.stripslashes($_POST[‘state’]);
$msg = “$namenn”.”$emailn”.”$celln”.”$aimnn”.”$addn”.”$add2n”;
if(mail(“$recipient”,”$subject”,”$msg”))
echo nl2br(“<p align=’center’>
<b>Message Sucessfully Sent!</b>
<i>Click the banner above to return to our site!</i>
</p>

);
else
echo “Message failed to send”;
}
?>

</td>
</tr>
</table></td>
</tr>

</table>
<div align=”center” class=”style2″>
<pre><span class=”style3″>Copyright &copy; 2008 Matt McClay;
All Rights Reserved</span></pre>
</div>
<div align=”left”></div>
</body>
</html>
[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscSep 30.2008 — You can't do a redirect in this script because it is in the middle of an HTML file, i.e. after headers have been sent. The best thing to do is to put your form-handling script in a separate .php file, submit your form to that script, and at the end of that script add this:

[code=php]
header("Location: http://www.yoursite.com");
[/code]


For more information, check this out
Copy linkTweet thisAlerts:
@ShortsSep 30.2008 — aj_nsc is right, redirects in PHP must be before the headers are sent out (same as for COOKIES).

If that would be a problem for you to do with this page, you can redirect with JavaScript.

[CODE]
<script type="text/javascript">
/* <![CDATA[ */
function init() {
window.location = 'URL';
}
window.onload = init;
/* ]]> */
</script>
[/CODE]
Copy linkTweet thisAlerts:
@JCB1985authorSep 30.2008 — Well, it looks like I need to re-vamp this page, and put my PHP in a separate file. Is there anywhere I could find a good form-handling script for a PHP file that I could tweak?

Thanks a million!

Matt
×

Success!

Help @JCB1985 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...