Ryan's District
December 01, 2008, 11:47:13 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Ryan's District Lottery: Claim your ticket or check
Jackpot details  
 
   Home   Help Search Chat Calendar Chess Shop Login Register  
Digg This!
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: Saving with PHP  (Read 807 times)
0 Members and 1 Guest are viewing this topic.
Sup3rkirby
Newbie
*

Reputation: 1
Offline Offline

Gender: Male
Posts: 3
9711.39 RD$

View Inventory
Send Money to Sup3rkirby


View Profile Awards
« on: September 04, 2007, 08:45:24 PM »

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.

Code:
<?
$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";
?>
Logged

"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."
Ryan's District
« on: September 04, 2007, 08:45:24 PM »

 Logged
Sup3rkirby
Newbie
*

Reputation: 1
Offline Offline

Gender: Male
Posts: 3
9711.39 RD$

View Inventory
Send Money to Sup3rkirby


View Profile Awards
« Reply #1 on: September 06, 2007, 05:59:32 PM »

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.

Code:
<?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;
?>
Logged

"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."
UnRegistered
Guest Username
Guest
Hero Member
*

Reputation: 724
Offline Offline

Posts: 18627
1060.35 RD$

View Inventory
Send Money to UnRegistered

Guest Account


View Profile WWW Awards
« Reply #2 on: September 07, 2007, 12:06:49 AM »

so have it worked  Huh?

what is ur site ? i like to see it live 
Logged

This username is a public Guests username
This means every one can use.
It have permissions like guests .
By using it you can remain anonymous to everyone exept staff members
Username : UnRegistered
Password : password
Sup3rkirby
Newbie
*

Reputation: 1
Offline Offline

Gender: Male
Posts: 3
9711.39 RD$

View Inventory
Send Money to Sup3rkirby


View Profile Awards
« Reply #3 on: September 07, 2007, 04:11:54 AM »

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

"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."
UnRegistered
Guest Username
Guest
Hero Member
*

Reputation: 724
Offline Offline

Posts: 18627
1060.35 RD$

View Inventory
Send Money to UnRegistered

Guest Account


View Profile WWW Awards
« Reply #4 on: September 08, 2007, 12:39:20 AM »

so is the prob fixed as far as i can see
Logged

This username is a public Guests username
This means every one can use.
It have permissions like guests .
By using it you can remain anonymous to everyone exept staff members
Username : UnRegistered
Password : password
sunite
Admin
Hero Member
*****

Reputation: 65535
Offline Offline

Posts: 7275
18464.75 RD$

View Inventory
Send Money to sunite


View Profile WWW Awards
« Reply #5 on: September 29, 2007, 01:03:22 PM »

ShoutBox looks good
Logged

The Network:-
You are not allowed to view links.
Register or Login
X
You are not allowed to view links.
Register or Login
X
You are not allowed to view links.
Register or Login
X

You are not allowed to view links.
Register or Login
X
You are not allowed to view links.
Register or Login
X
You are not allowed to view links.
Register or Login
X

You are not allowed to view links.
Register or Login
X
You are not allowed to view links.
Register or Login
X
You are not allowed to view links.
Register or Login
X

You are not allowed to view links.
Register or Login
X
You are not allowed to view links.
Register or Login
X
You are not allowed to view links.
Register or Login
X

You are not allowed to view links.
Register or Login
X

You are not allowed to view links.
Register or Login


FindTheWeb Production at You are not allowed to view links.
Register or Login
Joelle
Hero Member
*****

Reputation: 10899
Offline Offline

Gender: Female
Posts: 7827
7349.02 RD$

View Inventory
Send Money to Joelle

Ryan's District


View Profile Awards
« Reply #6 on: April 13, 2008, 10:53:24 AM »

link is broken  Sad
Logged
Ryan's District
   

 Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Archive - WAP2 - WAP - imode
Sponsors: RAYAN.tv
-

Powered by MySQL Powered by PHP Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.633 seconds with 29 queries.

Google visited last this page Today at 06:40:42 AM