I need a loop in here somewhere and for some reason its just writing the word 'array' to the file and not whats in my input boxes.... also I need another page that can produce this data in individual <td> on a table - any ideas please? <?php $saving = $_REQUEST['saving']; if ($saving == 1) { $data = $_POST["customer"] ; $file = "test2.txt"; $fp = fopen($file, "w") or die("Couldn't open $file for writing!"); fwrite($fp, $data) or die("Couldn't write values to file!"); fclose($fp); echo "Saved to $file successfully!"; } ?> <form name="form1" method="post" action="http://www.website.com/test2.php?saving=1"> <input type="text" name="customer[1][datefrom]"> <input type="text" name="customer[1][dateto]"> <input type="text" name="customer[1][availability]"> <input type="text" name="customer[1][prince]"> <input type="text" name="customer[2][datefrom]"> <input type="text" name="customer[2][dateto]"> <input type="text" name="customer[2][availability]"> <input type="text" name="customer[2][prince]"> <input type="text" name="customer[3][datefrom]"> <input type="text" name="customer[3][dateto]"> <input type="text" name="customer[3][availability]"> <input type="text" name="customer[3][prince]"> <?php $file = "test2.txt"; if (!empty($file)) { $file = file_get_contents("$file"); echo $file; } ?> <br> <center><input type="submit" value="Save"></center> </form> PHP:
I would assume this is because $data is an array (because of the values of the 'name' tag, it'll return an array) whereas fwrite takes a (string) as the second parametre. Implode it, or otherwise convert it to a string, otherwise you'll only return 'Array'. Best of luck! Dan
Heh Dan, thanks for the reply - can you give me an example please? I'm trying to write the data that's in the 9 input boxes and also how can I reproduce them in a table?????
To see what I mean, try print_r($data); Then create a string with all the relevant data in. E.g. echo "<tr><td>{$customer[1]['datefrom']}</td>..."; Obviously using double quotes and embedded variables isn't the fastest way, but the I'm sure the minutes you save writing it will override the millisecond you lose running it.
hahah good joke..... I'm a complete php novice trying to learn it as I go. Where should I put that code in? THANKS FOR THE HELP