Jump to content

Flat-file PHP form question


martinstan

Recommended Posts

Hi
I'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.htm

Now 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.
Thanks
Martin
Link to comment
https://forums.phpfreaks.com/topic/31473-flat-file-php-form-question/
Share on other sites

By the way Merry Christmas ;D

Ok 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.php

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

Thanks
Martin

Here 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="&pound;" 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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.