Hello everyone,
I am currently working on a control panel for some people who know nothing whatsoever about webpage editing to be able to edit the menu I have posted on their website. I use text file includes to display all the information on the site and I need help with saving the edited data for each section back to its original file. I already have a form set up that inserts new items into the file and then displays the entries below the form within textfields/textareas for editing. The only thing I’m stuck on is how to write each entry that’s listed below the add new entry form back into the file it was read from.
Here is the test form: http://bippys.romas-ellicottcity.com/test/addedit.php
And here is the code I’m using:
[php]
<input type=‘text’ name=‘item’ value=’”.$item[‘0’]."’><a href=".$_SERVER[‘PHP_SELF’]."?action=deleteline&line=".base64_encode($value).">Delete | <input type='text' size='4' name='price' value='".$item['2']."' | |
".$item['1']." | ||
And this is the code that adds the info into the db:
[php]<?
$item = $_POST[‘item’];
$desc = $_POST[‘desc’];
$price = $_POST[‘price’];
$section = $_POST[‘section’];
switch ($section){
case “app”:
$file = “appetizers”;
break;
case “soup”:
$file = “soups”;
break;
case “sides”:
$file = “sides”;
break;
case “sandwiches”:
$file = “sandwiches”;
break;
case “entrees”:
$file = “entrees”;
break;
case “test”:
$file = “test”;
break;
}
$line = array($item, $desc, $price);
$delimited = implode("|", $line);
$myFile = “test.txt”;
$fh = fopen($myFile, ‘a+’) or die(“can’t open file”);
fwrite($fh, “\r\n”.$delimited);
fclose($fh);
header (“location:addedit.php”);
?>[/php]
PS - I haven’t coded anything in about 5yrs and I was still a noob when I left off… I’m sure there are tons of more efficient ways of accomplishing this, but I would like to use flat files
Any help would be greatly appreciated!