Page 1 of 1

Real Quick What is wrong with this code...?

Posted: Wed Jun 14, 2006 3:46 pm
by tecktalkcm0391
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?

Posted: Wed Jun 14, 2006 3:50 pm
by Ollie Saunders
I don't know what you are thinking there:

Code: Select all

$date = date("G""i""s""m""n""Y");
that should be

Code: Select all

$date = date("G i s m n Y");
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'];

Re: Real Quick What is wrong with this code...?

Posted: Wed Jun 14, 2006 3:54 pm
by RobertGonzalez
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.

Posted: Wed Jun 14, 2006 5:25 pm
by feyd
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:
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.

Posted: Wed Jun 14, 2006 5:31 pm
by Christopher
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:

Code: Select all

$date = date("G""i""s""m""n""Y");
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.