Jump to content

j0mby

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

j0mby's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Man! That's exactly what I needed. Thanks HaLo2FrEeEk! And I appreciate the critique of my previous plan, atacus. I will definitely take the time to check out mysql. thanks guys. this forum has been helpful.
  2. thanks for the "help", magnetica. can anyone else actually help me with my code instead of judging me for not being an ace at php coding after 3 weekends of messing around with it? Any real advice is greatly appreciated.
  3. OK. So you recommend I take the time to code this using a mysql database, so I'll check out some tutorials. Thanks. However, can anyone tell if what I was trying to do would work if I could get the coding right? I don't know why it won't write the post data along with string/array data into the file... anyway, thanks for the help.
  4. I was assuming it would be harder (and take longer) to accomplish, since I don't know much about mysql. I was only trying to "throw it up there", and then probably, down the road, replace it with one that uses a mysql database. but if it's just a few more steps to do that, and the way I'm trying to do it now is silly, I'd take your advice and do some mysql tutorials, etc. But I was also curious as to why what I'm trying to do isn't working. I've learned a lot about php by trying it, so it's not all a loss.
  5. I'm trying to make a very simple comments page on my site using PHP and am having problems somewhere. I am very new to PHP. I was able to create one that works with comments appended, but I want the latest comment to be on top, and that's where I'm running into trouble. Since I know very little about PHP, I thought I was clever in what I came up with. I think it can work if I get the coding right. Let me know if my logic is wrong. I'm working on a mac OS X and writing it all in simple text, but when I have time at work, I am messing around in Notepad on a PC. I get almost all of my code from tutorials and some here and there from forums. What I've done is start with a simple form. Then it goes to the first comments page, comments.php This form retrieves the form data, opens the first text file (comments.txt) and reads it. Then it opens the second file (comments2.txt) and is supposed to write the form data at the top and the already saved data (from comments.txt) underneath it. This file also writes the form data to a database (which seems to be working) and is also supposed to echo 'thanks for your comment, $name (which isn't working). Then after 5 seconds it sends you to the second PHP doc. The second PHP doc (fanscomments.php) then opens the comments2.txt file and echos it and also opens the comments.txt doc and writes over it with comments2.txt In this way, I was thinking it should result in the latest comment posting on the top when the whole loop is completed. I know this is a clumsy way of doing this, but as I said, I'm new to coding and wanted to have something functional, and then replace it later with something more sophisticated. Here is the first PHP page: <?php if(!empty($_SERVER['HTTP_REFERER'])) header('Refresh: 5,URL="/fanscomments.php"'); // retrieve form data $input = $_POST['name']; $input = $_POST['eaddress']; $input = $_POST['comments']; // define variables $name = "$_POST[name]"; $comments = "$_POST[comments]"; $eaddress = "$_POST[eaddress]"; echo 'Thanks for your comment, $name!'; // set file to read $file = '/home/content/s/c/o/scodeath/html/fans/comments.txt'; // open file $fh = fopen($file, 'r') or die('Could not open file!'); // read file contents $commentsdata = fread($fh, filesize($file)) or die('Could not read file!'); // close file fclose($fh); $out = fopen("/home/content/s/c/o/scodeath/html/fans/comments2.txt", "w"); if (!$out) { print("Could not append to file. Please try again later, or send an email to fans@summercampofdeath.com"); exit; } fputs($out,"\"$_POST[comments]\"\n\n"); fputs($out,"-$_POST[name]\n\n\n\n"); fwrite($out, $commentsdata); fclose($out); $out = fopen("/home/content/s/c/o/scodeath/html/fans/commentsdb.txt", "a"); if (!$out) { print("Could not append to file. Please try again later, or send an email to fans@summercampofdeath.com"); exit; } fputs($out,"$_POST[name]\t"); fputs($out,"$_POST[eaddress]\t"); fputs($out,"$_POST[comments]\t"); fputs($out,"$_SERVER[REMOTE_ADDR]\n\n"); fclose($out); ?> And here is the second PHP page: <html> <head></head> <body> <?php // set file to read $file = '/home/content/s/c/o/scodeath/html/fans/comments2.txt'; // read file into array $data = file($file) or die('Could not read file!'); // loop through array and print each line foreach ($data as $line) { echo nl2br($line); } $out = fopen("/home/content/s/c/o/scodeath/html/fans/comments.txt", "w"); if (!$out) { print("Could not append to file. Please try again later, or send an email to fans@summercampofdeath.com"); exit; } fputs($out,"$data\n\n"); fclose($out); ?> </body> </html> I sure appreciate the help! BTW, why is it printing the word - Array in my webpage? Thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.