Log in

View Full Version : very new to php... link question



Rohan72
01-30-2007, 09:03 PM
I'm very new to php.
For a website I created I want the users to be able to sent a string to an email address and when they are done, to be redirected to another page (html-page).

I created a html page with a form that calls a php page. Both scripts work perfectly, but for now they just give a message after sending.
How can I replace the "echo" to make the script go to another html-page?
I'm learning from th "php5 and MySQL bible", but i can't find this anywhere... yet :(



<form method="post" action="masc.php">
A name for our mascotte...<br>
<input type="text" size="30" name="Mascotte"><br>
<input type="submit" name="Submit" value="Send"><br>
</form>


<?php
$Mascotte = $_POST['Mascotte'];
$formsent = mail('mascotte@email.com','Name Mascotte',$Mascotte);
if ($formsent) {
echo "Thanks!";
} else {
echo "try again";
}
?>

djr33
01-31-2007, 01:42 AM
header('Location: url');
OR
echo a meta tag--
echo '<meta http-equiv="refresh" content="0;newurl">
Note that '0' is delay, in seconds.... 5= 5 seconds, etc.

Rohan72
01-31-2007, 08:04 PM
I tried both options.

header leaves me with a blank page (no matter what page i refer to),
and the echo - meta combo gives me an endless reloading of the current php-page.

I also tried the fopen() command... same result as header.

Here are both complete pages.

http://www.bluearmyneerpelt.be/mascotte.html

<<html>
<head>
<title>Mascotte</title>
</head>

<body>
<form method="post" action="masc.php">
Een gepaste naam voor onze mascotte...<br>
<input type="text" size="30" name="Mascotte"><br>
<br>
<input type="submit" name="Submit" value="Verzend"><br>

</form>

</body>
</html>



http://www.bluearmyneerpelt.be/masc.php

<html>
<head>
<title>Untitled Document</title>
</head>

<body>
<?php
$Mascotte = $_POST['Mascotte'];
$formsent = mail('mascotte@testmail.be','Naam Mascotte',$Mascotte);
// I didn't include my real mail, in order not to get tons of mails
if ($formsent) {
echo '<meta http-equiv="refresh" content="0; http://www.bluearmyneerpelt.be/">';
} else {
header('location: http://www.bluearmyneerpelt.be/mascotte3.html');
}
?>
</body>
</html>

djr33
01-31-2007, 10:35 PM
Uh... the meta tag is weird then.
You should be going to a NEW page, or, yes, it will keep refreshing (as says the name) at the interval in seconds.

Location should work.

Thoughts:
1. There is NO SPACE in the meta tag. This may be the entire problem, and the browser doesn't see it correctly.
2. the L in Location should be CAPITALIZED...
3. Location and other headers WILL NOT FUNCTION if you have already sent any html/text data. The headers come first, then the content. You must do that at the TOP of your page, before the <html>... tags.

See if either/both of those fix it.

I hope this solves it. Note: I'm fairly out-of-it at the moment, so I'm just trying to be clear/coherent... not yelling at you.

Rohan72
02-04-2007, 03:41 PM
the Header still doesn't work..
META was a mistake on my part... I forgot to put URL= in front of the actuall address.
So.. problem solved