Forum Moderators: coopster

Message Too Old, No Replies

PHP thank you page

         

Morgan19

6:28 pm on Dec 2, 2004 (gmt 0)

10+ Year Member



I have a page with a little holiday "game" on it, that I'd like to then go to a thank you page once the user clicks Submit.

I've got everything set up but when I click the submit button I get this error:

-----------------------------------
Parse error: parse error, unexpected T_VARIABLE in /home/httpd/vhosts/example.com/httpdocs/holiday2004/thanks.php on line 144
-----------------------------------

I know how to make forms (using DW MX 2004, which I am) but don't really know PHP. I'm following some instructions from another website so I'm not exactly sure what's wrong.

This is the game page:

<snipped>

I'd post the link to the .php page as well, but it just comes up as an error. Basically it's like any other page on the site except the instrucitons had me add this in the body:

<SCRIPT LANGUAGE="php">
$email = $HTTP_POST_VARS[email];
$mailto = "user@example.com";
$mailsubj = "Form submission";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form:\n";
while (list ($key, $val) = each ($HTTP_POST_VARS)) {
$mailbody .= "$key : $val\n"; }
mail($mailto, $mailsubj, $mailbody, $mailhead);
</SCRIPT>

Thanks,
m19

[edited by: coopster at 9:17 pm (utc) on Dec. 2, 2004]
[edit reason] removed urls per TOS [webmasterworld.com] [/edit]

baze22

6:45 pm on Dec 2, 2004 (gmt 0)

10+ Year Member



Does the code you posted include line 144 from thanks.php? If not post line 144 and the code immediately before it.

I tried what you had here and was able to run it without error.

baze

olwen

6:48 pm on Dec 2, 2004 (gmt 0)

10+ Year Member



For a start change:

$email = $HTTP_POST_VARS[email];

to
$email = $HTTP_POST_VARS['email'];

Morgan19

6:52 pm on Dec 2, 2004 (gmt 0)

10+ Year Member



These are the lines:

143 - <SCRIPT LANGUAGE="php">
144 - $email = $HTTP_POST_VARS[email];
145 - $mailto = "user@example.com";
146 - $mailsubj = "Form submission";
147 - $mailhead = "From: $email\n";
148 - reset ($HTTP_POST_VARS);
149 - $mailbody = "Values submitted from web site form:\n";
150 - while (list ($key, $val) = each ($HTTP_POST_VARS)) {
151 - $mailbody .= "$key : $val\n"; }
152 - mail($mailto, $mailsubj, $mailbody, $mailhead);
153 - </SCRIPT>

Olwen, I also changed what you mentioned but to no effect, still get the error.

m19

[edited by: coopster at 9:18 pm (utc) on Dec. 2, 2004]
[edit reason] generalized url [/edit]

dcrombie

6:56 pm on Dec 2, 2004 (gmt 0)



Try deleting lines 143 and 153.

Then if that doesn't work, use:

143: <?PHP

...

153:?>

baze22

6:57 pm on Dec 2, 2004 (gmt 0)

10+ Year Member



Still don't see the problem but try this:

<?php
$email = $HTTP_POST_VARS[email];
$mailto = "user@example.com";
$mailsubj = "Form submission";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form:\n";
while (list ($key, $val) = each ($HTTP_POST_VARS)) {
$mailbody .= "$key : $val\n"; }
echo "($mailto, $mailsubj, $mailbody, $mailhead)";
?>

baze

[edited by: coopster at 9:26 pm (utc) on Dec. 2, 2004]
[edit reason] generalized url [/edit]

baze22

7:00 pm on Dec 2, 2004 (gmt 0)

10+ Year Member



Guess I should have asked about the code immediately before this code block.

baze

Morgan19

7:03 pm on Dec 2, 2004 (gmt 0)

10+ Year Member



I tried the first and second suggestions (removing the start/end PHP lines altogether and then changing them to <? instead). This time when I click submit it loads through to the thanks.php page, but just lists all that on the page as text... I'm trying to get an email to come through to me as well, which I thought the coding in the form was supposed to do.

m19

baze22

7:06 pm on Dec 2, 2004 (gmt 0)

10+ Year Member



Oops, in my test I undid the mail and echo'd the variables instead. Need to change back the line that reads

echo "($mailto, $mailsubj, $mailbody, $mailhead)"; 

to

mail ($mailto, $mailsubj, $mailbody, $mailhead);

baze

Morgan19

7:08 pm on Dec 2, 2004 (gmt 0)

10+ Year Member



Yahoooooo! That worked. :) I've been trying to figure this out for hours, thank you! :):)

m19

Morgan19

7:20 pm on Dec 2, 2004 (gmt 0)

10+ Year Member



So why did changing it from a script tag to the <? one make a difference?

m19

coopster

9:45 pm on Dec 2, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Morgan19.
Welcome to WebmasterWorld, baze22.

If I remember correctly, when you create a PHP page in Dreamweaver, it will start PHP code with an xml DOCTYPE declaration, thereby serving up the page as XML/XHTML. And if you intend to embed PHP code in XML or XHTML, you will need to use the <?php. . .?> form of Escaping from HTML [php.net] to conform to the XML.