Mistake of the Day (Help Please)

J03

~~~~~~~~
Messages
5,558
Location
Wales
Okay - i am sure that the code i need to write is very similar to to code that root posted on this thread.

What i am gonna try to make is a thing on my website, where people submit a mistake that they made on that day, and display it. i need to make a user form, on which they cam type there name, and there mistake. When they press the sumbit button, i want it write the date, their name, and their mistake to a file (i am sure a .txt file will do), and on another page, i want it to echo that day's mistakes. dont think it will be too hard to do, but i dont quite know enough php to do what i want... Thanks in advance

Samurai!!!
 
urmm...

(if I remember correctly from stuff you've posted before)...

I hope that I'll be able to give you enough help simply by saying this...

to log things in a text file us
$filepointer = fopen("filename", 'a'); (a for append) -so it'll add to the end.

then use fwrite to write the text into the file (use fwrite in (pretty much) the same way you'd use print.

then to save and close use fclose (file pointer)...

whilst I've not outright given you code, I hope that I've given you enough in a five minute post before I go have my dinner...

if you have an confusion about the function then either:
look them up in the php manual on the php.net site...

or come back here and I'll help you out a little more...

(reading back the file can either be done with fopen("filename", "r") or linknig the file with a url as the example I gave before).
 
Code:
$datestring = date('d/m/Y');

print "$datestring";
the dmY specifies the format of the date,
there are lots of things that you can put there.

eg = d/m/Y = 20/05/2006
D - d/m/y = Sat - 20/05/06


you can include dates, days times all in full english, 3letter day representation, 12 hour or 24 hour clocks...

find out more here.
http://uk2.php.net/manual/en/function.date.php
 
Hmm, it didnt work, i will post the code when i can find it! (How can i loose somthing from yesterday?!?!?)

-edit-
BTW 200th Post!!
 
Okay, i have a HTML form that sumbits to This code:

PHP:
<?php
$datestring = date ('d/m/Y')
$postdata $_POST['motdtxt'];
$stufftoadd = "$datestring $postdata \n";

$file = 'motd.txt'
$file = fopen($file, 'a');
fwrite($file, $stufftoadd);
fclose($file);

?>
It is SUPPOSED to write the Date, then the day's mistake to motd.txt, But it dont work :(

and another piece, which is supposed to display the current days mistake:
PHP:
<?php
$url = "motd.txt";
$file = file($url); //open file for reading
for ($line=0;$line<=sizeof($file);$line++) //look at lines, one at a time from zero to the end of the file
{
  if (ereg("date ('d/m/Y')", $file[$line])) //look for the regular expression Name:
  {
	$temp = split(":", $file[$line]); //split the line on a common charector (:)
	print "name = $temp[1]<br>"; //print the sceond part of the split array as this is the name
  }
}
?>

Please Help! Thanks in advance.

-edit-
Sorry for double post
 
I love PHP...but I am not too good with using txt files...I always thought and still think that using MySQL databases are more efficient and less exposed.

In this
<?php
$datestring = date ('d/m/Y')
$postdata $_POST['motdtxt'];
$stufftoadd = "$datestring $postdata \n";

$file = 'motd.txt'
$file = fopen($file, 'a');
fwrite($file, $stufftoadd);
fclose($file);

?>

I think it is supposed to be something like this:
<?php
$datestring = date ('d/m/Y');
$postdata = $_POST['motdtxt'];
$stufftoadd = "$datestring $postdata \n";

$file = 'motd.txt';
$file = fopen($file, 'a');
fwrite($file, $stufftoadd);
fclose($file);

?>

Although as I said I am not that great with this stuff, if I were you I would use a MySQL database, I could definitely help you out there.
 
Back
Top Bottom