martinstan Posted December 21, 2006 Share Posted December 21, 2006 HiI'm pretty new to PHP but beginning to get the bug. I've been having a play with the $_POST global and have created a very simple form that uses this method. It would be a very simple solution to a small project I'm working on, however it is flawed. Here is the basic form:http://www.six22.co.uk/pricelist/pricelist.htmNow if you fill in the fields then submit, they update another PHP page: prices.php. Pretty cool.What I want to do is take this a stage further. Is it possible to save these fields to another file in order to manage a simple pricelist online?I know this is easy to remedy using a database but is it possible using a flat-file or some other method without having to use a database.I'd be really interested in anyones advice, thoughts or solutions.ThanksMartin Quote Link to comment Share on other sites More sharing options...
trq Posted December 21, 2006 Share Posted December 21, 2006 You can write to a file using a combination of [url=http://php.net/fopen]fopen[/url] and [url=http://php.net/fwrite]fwrite[/url]. Quote Link to comment Share on other sites More sharing options...
martinstan Posted December 22, 2006 Author Share Posted December 22, 2006 By the way Merry Christmas ;DOk Thorpe, you sent me off with some good info there and I've managed to put together (using various tutorials) quite a good little flat file database. This has now raised a few more questions from me and I'm hoping for some equally good leads.Here is my basic list:http://www.six22.co.uk/flatfileform/pricelist.phpBy the way...this is the sort of stuff my wife does, not me ::)The list works great but there are again some obvious constraints. Here is a list of things I'd like to be able to do to this. For instance: [list][*]None of this list is editable without physically altering the flat-file. Is this possible to create an edit page.[*]Again there is no way to add another item, for instance 'back, sack and crack :o' to the waxing category. Any thin added by my form just gets added to the end.[*]Also by pure luck, not design, the underlining in each section is caused by the fact that there is no heading text, so it's just a 1px line of background. Not good. It would be nice to give each category it's own heading.[/list]I'm not even sure that this kind of stuff is possible with such a simple db but it would be pretty cool if it was. I'd be grateful for any suggestion for my little project.ThanksMartinHere is all the code:The form:(info.php)[code] </head><body><DIV align="center" style=" margin-top:30px; "><form action="sendinfo.php" method="get"> <p class="tdcontent">Heading:<br /> <input name="heading" type="text" size="40"> <br/><br/>Treatment:<br /> <input name="treatment" type="text" size="40"> <br /><br/> Price:<br /><input name="price" type="text" value="£" size="15"><br /><br/><input type="submit" value="update"><input type="reset" name="Reset" value="Reset"></p></form></DIV></body></html>[/code]the send file:(sendinfo.php)[code]<body><?php$heading = $_GET["heading"];$treatment = $_GET["treatment"];$price = $_GET["price"];print("<b>Thank You!</b><br />Your information has been added! You can see it by <a href=pricelist.php>Clicking Here</a>");$out = fopen("savedinfo.txt", "a");if (!$out) {print("Could not append to file");exit;}fputs ($out,implode,("\n"));fwrite($out, $heading . "||". $treatment ."||" . $price ."\n");fclose($out);?></body></html>[/code]the list: (pricelist.php)[code]<link href="pricelist.css" rel="stylesheet" type="text/css"><? $addlink = '<a href = "info.php">Add another treatment</a>'; $userinfo = file("savedinfo.txt"); echo '<table class="tablestyle" width = 400px>';foreach ($userinfo as $key => $val) { $data[$key] = explode ("||", $val);}for ($k = 0; $k< sizeof ($userinfo); $k++) { echo '<tr><td class = "tdheader" colspan =2>' . $data[$k][0]. '</td></tr>'; //this is the header echo '<tr><td class = "tdcontent">' . $data[$k][1]. '</td><td class = "tdcontent">' . $data[$k][2]. '</td></tr>'; //this is the data} echo '</table>'; echo '<br/>'; echo $addlink;?>[/code] Quote Link to comment Share on other sites More sharing options...
martinstan Posted December 23, 2006 Author Share Posted December 23, 2006 Hisorry to bump this but I thought the subject may have been misleading.Martin 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.