aeonsky Posted February 15, 2007 Share Posted February 15, 2007 Hi! I just had a quick question about fwrite command. Basically what I'm doing is an order page that takes the info from forms and writes them to a txt file, which is the database. The other PHP file reads the info from the txt file and place the info into a table. I've got everything working except a little problem with fwrite. Each time it writes to a text file, it deletes everything (from the database file) and then writes the new info. I want to keep the old info and then add the new info. I've looked around the web to fix the problem, but couldn't find anything! Thank you very much for the time and consideration! P.S. Here's the code (I apologize, for probably writing the code in a horrific manner, I'm new at writing PHP, I can edit it very nicely though) : I need &next because it write a new line (and each new line in the txt file represents a new row in the table) and I need fwrite($fp, "|"); because each | sign represents a new cell in the table. <?PHP $next = " "; $name = $_REQUEST['name'] ; $room = $_REQUEST['room'] ; $order = $_REQUEST['order'] ; $arrangement = $_REQUEST['arrangement'] ; // Open the file and erase the contents if any $fp = fopen("admin/db.txt", "w"); // Write the data to the file fwrite($fp, $next); fwrite($fp, $name); fwrite($fp, "|"); fwrite($fp, $room); fwrite($fp, "|"); fwrite($fp, $order); fwrite($fp, "|"); fwrite($fp, $arrangement); // Close the file fclose($fp); ?> Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 15, 2007 Share Posted February 15, 2007 Either read the data in the text file to a variable, then write that variable back to the file first, or change: $fp = fopen("admin/db.txt", "w"); to: $fp = fopen("admin/db.txt", "a"); Notice the change from "w" to "a" as the second parameter to fopen. http://www.php.net/fopen#id3485037 is a table that lists what all of the letters mean. Quote Link to comment Share on other sites More sharing options...
aeonsky Posted February 15, 2007 Author Share Posted February 15, 2007 Thank you very much! You guys are awesome! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.