Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 05-17-2006, 01:02 PM   #1
j03
~~~~~~~~
 
Join Date: Jan 2005
Location: Wales
Posts: 5,556
Send a message via MSN to j03
Default Mistake of the Day (Help Please)

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!!!
__________________

j03 is offline   Reply With Quote
Old 05-18-2006, 01:04 PM   #2
j03
~~~~~~~~
 
Join Date: Jan 2005
Location: Wales
Posts: 5,556
Send a message via MSN to j03
Default Re: Mistake of the Day (Help Please)

bump?
__________________

j03 is offline   Reply With Quote
Old 05-18-2006, 03:27 PM   #3
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,003
Default Re: Mistake of the Day (Help Please)

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).
__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 05-20-2006, 09:39 AM   #4
j03
~~~~~~~~
 
Join Date: Jan 2005
Location: Wales
Posts: 5,556
Send a message via MSN to j03
Default Re: Mistake of the Day (Help Please)

Thanks for that, but what is the pho code i need to echo the Date?
j03 is offline   Reply With Quote
Old 05-20-2006, 02:45 PM   #5
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,003
Default Re: Mistake of the Day (Help Please)

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
__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 05-20-2006, 05:09 PM   #6
j03
~~~~~~~~
 
Join Date: Jan 2005
Location: Wales
Posts: 5,556
Send a message via MSN to j03
Default Re: Mistake of the Day (Help Please)

Thanks soo much dude! You are a great help to everyone! *Starts making php stuff*
j03 is offline   Reply With Quote
Old 05-20-2006, 05:54 PM   #7
BSOD
 
MSFanBoy's Avatar
 
Join Date: May 2006
Posts: 190
Default Re: Mistake of the Day (Help Please)

Yeah root's the man.
MSFanBoy is offline   Reply With Quote
Old 05-21-2006, 05:54 AM   #8
j03
~~~~~~~~
 
Join Date: Jan 2005
Location: Wales
Posts: 5,556
Send a message via MSN to j03
Default Re: Mistake of the Day (Help Please)

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!!
j03 is offline   Reply With Quote
Old 05-21-2006, 12:50 PM   #9
j03
~~~~~~~~
 
Join Date: Jan 2005
Location: Wales
Posts: 5,556
Send a message via MSN to j03
Default Re: Mistake of the Day (Help Please)

Okay, i have a HTML form that sumbits to This code:

PHP Code:
<?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 Code:
<?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
j03 is offline   Reply With Quote
Old 05-21-2006, 01:24 PM   #10
BSOD
 
MSFanBoy's Avatar
 
Join Date: May 2006
Posts: 190
Default Re: Mistake of the Day (Help Please)

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.
__________________

MSFanBoy is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 08:18 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0