News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

Saving with PHP

Started by Sup3rkirby, September 04, 2007, 09:45:24 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Sup3rkirby

Hello.  I am essentially making a 'ShoutBox', where user can type their name and a message, and it is added to a file(on top).  Very similar to a guestbook, but simpler.

My problem is more than likely in my coding.  It doesn't seem to save a file at all.  I originally based this off of a counter script I wrote, which works, but it only opens a file and then increments a number and saves.  This script is a bit more involved.

I am trying to use AJAX to send the POST data as well, and I think there is a problem there as well, because this script doesn't echo any POST data, meaning it wasn't receieved.

If anyone has any idea what is wrong, I greatly appreciate it.

<?
$getName = $_POST['name'];                                        // Gets the user's name
$getInfo = $_POST['message'];                                     // Gets the new info
$tagInfo = "<div class='largeTitle'>" . "{$getName}" . " - " . date("d/m/Y") . "</div><div class='transparentClass'><div class='contentText'>" . "{$getInfo}" . "</div></div>";

$tagBook_file = ("tagBook.txt");                                  // File that contains the Tag Board
$TagBook = file_get_contents($tagBook_file);                      // Puts the board info in a var
$fp = fopen($tagBook_file , "w");                                 // Opens the file for additional info
fwrite($tagBook_file, "{$tagInfo}" . "" . "$TagBook");    // Writes the new info to the file
fclose($fp);                                                      // Closes the file
echo "http://sup3rkirby.zeeblo.com/tag/tagBook.txt" . "{$tagInfo}" . "" . "$TagBook";
?>
"Given billions of tries, could a spilled bottle of ink ever land in the words of Shakespere?"
"The Macintosh operating system is amazingly complex, given how little it does."

Sup3rkirby

Well, I think one problem I had were the file permissions.  But I have set those to '0666'.  Then I actually got the script to work.  It saved a file with the new contents on top, just like my PHP should do.

But then I manually reuploaded the .txt file via FTP.  Looking back in my cPanel account I can see that the file permissions are '0666', but for some reason, my script seems to be hanging....

My site uses AJAX to send and get information, and when I try to run this, the loading page comes up and never goes away.  I'm not sure why, but for some reason it seems the script is executed, but then something happens and it never finishes.

I have slightly modified my code since my original post, so I'll post that code here.  But the code still should work, it is probably just an issue now of letting the server sync with my files and permissions.

<?PHP

$getName = $_POST['name'];                                                 // Gets the user's name
$getInfo = $_POST['message'];                                              // Gets the new info

$Months = array("January","February","March","April","May","June","July","August","September","October","November","December");

$tagInfo = "<div class='smallTitle'>" . $getName . " - " . $Months[date("m")-1] . " " . date("d") . ", " . date("Y") . "</div><div class='contentText'>" . $getInfo . "</div>";


$tagBook = file_get_contents("tagBook.txt") or exit("Unable to open file for reading!");


$tagBook_file = "tagBook.txt";
$fp = fopen($tagBook_file, 'w') or exit("Unable to open file!");           // Opens the file for additional info
fwrite($fp, $tagInfo . "<br>" . $tagBook);                                 // Writes the new info to the file
fclose($fp);                                                               // Closes the file


echo "http://sup3rkirby.zeeblo.com/tag/tagBook.txt;
?>
"Given billions of tries, could a spilled bottle of ink ever land in the words of Shakespere?"
"The Macintosh operating system is amazingly complex, given how little it does."

ryanhibbard_soccermaster_601

so have it worked  ???

what is ur site ? i like to see it live  :)

Sup3rkirby

You are not allowed to view links. Register or Login

It seems to work now.  I had to change the file permissions to '0777'(or just 777 for some people).  I had them set at '0666', which should allow the script to read and write to the file for any user, but I found out that some servers can be funny about this, so you must set them to '0777'.


I am, however, having an unusual problem.  This occurs in both IE and Firefox(but sometimes it will work in Firefox).

The script runs with AJAX so that PHP will get the information and save a file.  Then PHP will return the location of the file and AJAX handles the rest to load that page into my website.  So once you add something new, you are then shown the new file(kind of like when you make a post, it loads the new post after you submit it).

The problem is that for some reason the browsers seem to be caching the files in some weird way.  If you add something new, you are taken to the page, but your new entry is not shown up.  But it was still added.  You are only seeing the file before your changes.  Even if you load a different content page, you still can't seem to load the new data unless you close the page(or window or browser(depending on your browser and version)), and then reload the site.  Then if you go to the 'TagBook' page you will see the newly added post.
"Given billions of tries, could a spilled bottle of ink ever land in the words of Shakespere?"
"The Macintosh operating system is amazingly complex, given how little it does."

batata_batinjein

so is the prob fixed as far as i can see

Sunite


Joelle