Jump to content

Validate?


mortalc

Recommended Posts

SOmething went wrong on this line:

if (isset($_POST['name'])) file_put_contents("Position.htm", "<div id=\"$_POST['name']\">"."<h3>".$_POST["name"]."</h3>"."</div>"."<small>".Date("d.M.Y", "H:i:s")."</small>"."<br />".$_POST["reply"]."<br />");

Link to comment
Share on other sites

What is "something" supposed to mean? The actual error message? The code around this line of code? If it's a parse error, it's usually not at the place of the error, but somewhere around it.

Link to comment
Share on other sites

Can you give us the exact error details?I would also do it something more like this:

if (isset($_POST['name'])) {	file_put_contents('Position.htm', '<div id="'.$_POST['name'].'><h3>'.$_POST['name'].'</h3></div><br /><small>'.date('d.M.Y', 'H:i:s').'</small><br />'.$_POST['reply'].'<br />');};

Link to comment
Share on other sites

date should also be lowercase
Functions are case-insensitive in PHP. I'm thinking more and more that the second argument of the date() function is illegal, but another, less likely problem would be the lack of writing permissions for Position.htm
Link to comment
Share on other sites

Yep, the second parameter in date() shouldn't have any quotes around it. Try:date('d.M.Y', H:i:s)

Functions are case-insensitive in PHP. I'm thinking more and more that the second argument of the date() function is illegal, but another, less likely problem would be the lack of writing permissions for Position.htm
Link to comment
Share on other sites

Err, the second parameter in date() should be a valid UNIX timestamp, not some string.P.S. it is never valid to write a string literal without quotes.

Link to comment
Share on other sites

Here is the error message:

PHP Error Message Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a3312652/public_html/Position.php on line 34
Will try suggested fixes now.Ed::faceslap:It should have been if $_POST['reply'] is set....Nope, something is still wrong.Wait - RobberBaron used {}. I thought they weren't used in PHP?Ed 2:Monster faceslap! I've just checked, and I never uploaded position.htm!
Link to comment
Share on other sites

I would also do it something more like this:
if (isset($_POST['name'])) {	file_put_contents('Position.htm', '<div id="'.$_POST['name'].'><h3>'.$_POST['name'].'</h3></div><br /><small>'.date('d.M.Y', 'H:i:s').'</small><br />'.$_POST['reply'].'<br />');};

One error in your code: you do not put a semi-colon after a curly brace.
Here is the error message:Wait - RobberBaron used {}. I thought they weren't used in PHP?Ed 2:Monster faceslap! I've just checked, and I never uploaded position.htm!
Of course the curly braces are used in PHP, but they are only required in compound statements. Yours wasn't one. Although not uploading the file would throw an error, the specified one is not related to this. Do check the manual for date.
Link to comment
Share on other sites

file_put_contents will create the file if it does not exist.The date function is certainly used incorrectly.As you can tell, trying to debug a long concatenated string with embedded function calls is PITA. Terse code is neither required nor generally useful in this environment. You have plenty of RAM and HD space. Use it.I strongly suggest building this string in multiple statements. Assign it to a variable, and pass the variable to file_put_contents. In addition, assign the return value of date() to a variable before adding it to the data string. Being able to var_dump variables is essential to debugging, as is the ability to comment out lines of code to see which ones are broken.

Link to comment
Share on other sites

Err, the second parameter in date() should be a valid UNIX timestamp, not some string.
You're absolutely right, I was mixed up there and goofed it up. It should either be a timestamp or an equivalent, or nothing (which will default to the current time). It would be something like: date('d.M.Y H:i:s') or date('d.M.Y H:i:s', $some_timestamp)
Link to comment
Share on other sites

One error in your code: you do not put a semi-colon after a curly brace.
That's not an error, it just translates to a "noop" (no operation). It's basically just a waste of time for PHP, but it's not an error.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...