jaybird84404 Posted October 13, 2009 Share Posted October 13, 2009 Hey everybody, Sorry, I am really new to PHP coding and such but a project kind of got thrust on me. I need to create a a form for people to input some information and then be able to collect the information. It would be preferred that when they hit the "submit" button that it saves to a file rather than email because we expect high volumes of responses and don't want to be flooded with emails. I have the form created, which you can see at http://bookstore.weber.edu/jaystest1.asp. The code is as follows: <html> <head> <title>Congratulations</title> <script> function ShowMenu(num, menu, max) { //num is selected value, menu is the name of the div, max is the number of divs for(i = 1; i <= max; i++){ //add number onto end of menu var menu_div = menu + i; //if current show if(i == num) { document.getElementById(menu_div).style.display = 'block'; } else { //if not, hide document.getElementById(menu_div).style.display = 'none'; } } } </script> </head> <body> <h3>Congratulations</h3> <form action="process.php" method="post"> Name (First & Last): <input name="Name" type="text" size="20"><br> Phone Extension: <input name="Phone" size="24" tpye="text"><br> Gift Item #: <input name="Item" size="30" tpye="text"><br><br> Select your preferred method of delivery: <br> <select id='deliverymethod' onChange="javascript: ShowMenu(document.getElementById('deliverymethod').value,'divColor', 6);"> <option value='0'>Please select one <option value='1'>Pick-up at bookstore <option value='2'>Deliver to my office <option value='3'>Deliver to my home </select> <div id='divColor1' style="display: none;"> </div> <div id='divColor2' style="display: none;"> <br>Office Number: <input name="officenumber" type="text" value="" size="5"><br> Mail Code: <input name="mailcode" type="text" value="" size="9"><br> </div> <div id='divColor3' style="display: none;"> <br>Street Address: <input name="street" type="text" value="" size="22"><br> City: <input type="text" name="city" value=""> State: <input name="state" type="text" value="" size="2" maxlength="2"><br> Zip Code: <input name="zipcode" type="text" value="" size="5" maxlength="5"><br> </div> <br><br> <input type="submit" value="Submit"> </form> </body> </html> I had been searching the internet tryping to find ways to get the information to be saved to a file, but haven't had any luck in doing so. Here is the PHP that I found and modified. I tried putting it both at the top of the main page, and also in the "process.php" site but nothing has worked. Any helped would be greatly appreciated! <?php $saving = $_REQUEST['saving']; if ($saving == 1){ $name = $_POST['name']; $phone = $_POST['phone']; $item = $_POST['item']; $officenumber = $_POST['officenumber']; $mailcode = $_POST['mailcode']; $street = $_POST['street']; $city = $_POST['city']; $state = $_POST['state']; $zipcode = $_POST['state']; $file = "webergifts.txt"; $fp = fopen($file, "a") or die("Couldn't open $file for writing!"); fwrite($fp, $name, $phone, $item, $officenumer, $mailcode, $street, $city, $state, $zipcode) or die("Couldn't write values to file!"); fclose($fp); echo "Saved to $file successfully!"; } ?> Link to comment https://forums.phpfreaks.com/topic/177593-saving-data-from-a-form-into-a-file/ Share on other sites More sharing options...
GKWelding Posted October 13, 2009 Share Posted October 13, 2009 a much much easier method, and much more sensible would be to store the information in a database, preferably MySQL. Link to comment https://forums.phpfreaks.com/topic/177593-saving-data-from-a-form-into-a-file/#findComment-936378 Share on other sites More sharing options...
mikesta707 Posted October 13, 2009 Share Posted October 13, 2009 you have to pass a string to fwrite, not a bunch of variables. im suprised you aren't getting an error. concatenate all your strings together into 1 string, than try Link to comment https://forums.phpfreaks.com/topic/177593-saving-data-from-a-form-into-a-file/#findComment-936386 Share on other sites More sharing options...
jaybird84404 Posted October 13, 2009 Author Share Posted October 13, 2009 you have to pass a string to fwrite, not a bunch of variables. im suprised you aren't getting an error. concatenate all your strings together into 1 string, than try Sorry, I'm really new to this. How do I combine all of my variables into 1 string? Link to comment https://forums.phpfreaks.com/topic/177593-saving-data-from-a-form-into-a-file/#findComment-936393 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.