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
tecktalkcm0391
DevNet Resident
Posts: 1030 Joined: Fri May 26, 2006 9:25 am
Location: Florida
Post
by tecktalkcm0391 » Wed Jun 14, 2006 3:46 pm
This keeps returing the error message:
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/www/submit.php on line 3
Code: Select all
<?php
if(isset($_POST['to']) && isset($_POST['from']) && isset($_POST['content'])){
$date = date("G""i""s""m""n""Y");
$filename = '' . $_POST['to'] . ''. $date . '' . $_POST['from'] . '';
$somecontent = '<!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">/n<head>/n<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />/n<title>Message for' . $_POST['to'] . 'from' .$_POST['from'] . '</title>/n</head>/n<body>/n'. $_POST['content'] . '';
if (!$handle = fopen($filename, 'x')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Your message for ". $_POST['to'] .'was created!';
echo "You need to but this text in the comment to the user you want to send the message to: /n<textarea name=\"code\" cols=\"40\" rows=\"5\" id=\"textarea\">Your comment is here: <a href=\"http://myspacecomments.awardspace.com/" .$filename. "\">http://myspacecomments.awardspace.com/" . $filename . "</a> </textarea>";
fclose($handle);
} else {
print("Sorry, your missing data, please go back and try again");
}
print('<br><br><p align="center"><script type="text/javascript"><!--
google_ad_client = "pub-3154346307420490";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as_rimg";
google_cpa_choice = "CAAQiYaYhAIaCJ2wcuQYTrQ_KOm293M";
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br />
<br>
<script type="text/javascript"><!--
google_ad_client = "pub-3154346307420490";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="7349305414";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>');
?>
What is the error?
Ollie Saunders
DevNet Master
Posts: 3179 Joined: Tue May 24, 2005 6:01 pm
Location: UK
Post
by Ollie Saunders » Wed Jun 14, 2006 3:50 pm
I don't know what you are thinking there:
that should be
You might have problems with the next line too:
Code: Select all
$filename = '' . $_POST['to'] . ''. $date . '' . $_POST['from'] . '';
If you don't you really should because frankly its a little on the crazy side. try:
Code: Select all
$filename = $_POST['to'] . ' '. $date . ' ' . $_POST['from'];
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Wed Jun 14, 2006 3:54 pm
Change this...
Code: Select all
<?php
if(isset($_POST['to']) && isset($_POST['from']) && isset($_POST['content'])){
$date = date("G""i""s""m""n""Y");
$filename = '' . $_POST['to'] . ''. $date . '' . $_POST['from'] . '';
?>
...to...
Code: Select all
<?php
if(isset($_POST['to']) && isset($_POST['from']) && isset($_POST['content'])){
$date = date("G i s m n Y");
$filename = "{$_POST['to']} $date {$_POST['from']}";
?>
I would also add that you should be validating your form inputs. What you are doing in that code is more than a little dangerous in my opinion.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jun 14, 2006 5:25 pm
tecktalkcm0391, please, for the love of all things sane and fluffy, carefully choose your thread titles "Real Quick What is wrong with this code...?" tells us nothing.
There's this too:
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Wed Jun 14, 2006 5:31 pm
And for the love of all things sane and fluffy, if the error message says line 3 has some kind of error with strings -- and line 2 (because errors are often caused on the preceeding line) or line 3 looks like this:
Take a momemt to look at the string portion of that line for any potential problems, no matter how subtle they might be. And then take another moment and look at it again. Then take a third moment to think of a descriptive title for your post.
(#10850)