Saving data from a form into a file


Posted on 16th Feb 2014 07:03 pm by admin

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:

Code: <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">

Phone Extension: <input name="Phone" size="24" tpye="text">

Gift Item #: <input name="Item" size="30" tpye="text">


Select your preferred method of delivery:


<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;">

Office Number: <input name="officenumber" type="text" value="" size="5">

Mail Code: <input name="mailcode" type="text" value="" size="9">

</div>

<div id='divColor3' style="display: none;">

Street Address: <input name="street" type="text" value="" size="22">

City: <input type="text" name="city" value="">
State: <input name="state" type="text" value="" size="2" maxlength="2">

Zip Code: <input name="zipcode" type="text" value="" size="5" maxlength="5">

</div>




<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!

Code: <?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!";

}
?>

No comments posted yet

Your Answer:

Login to answer
59 Like 26 Dislike
Previous forums Next forums
Other forums

Mysql error message
help me find out what this error message means:

"Duplicate entry '0' for key 'PRIMARY'&q

tag inside php...
hi


Code: <?php
echo "<td width="$columnWidth%" align=&

Help: problem with Headers to download PDF file
Hi,

I'm trying to implement a script where when a user clicks a link he gets a PDF file to op

Simple code help with redirects
I am trying to figure out a redirect script that detects if the browser is IE 7 and if it does, redi

get multiple rows
Hi I want to get multiple rows from a db

I am using this for the db query
Code: public

Adding delete feature to my forum
Hello I am currently trying to add a delete feature to my forum. I believe I have everything built r

a very simple php header question (sorry!)
Firstly...I do apologise if this annoys anyone....a header error

I'm do not know php &

How to schedule the a job?
Hi,
I have prepared a task ( i.e. a procedure is prepare the file and send the same to con

b+ tree
Hi
can every body help me about b+ tree ?(insert & delete)

FILTER_CALLBACK -- Files?
Hi All,

I'm using the php filter functions to validate my form data. For custom filters, I'm

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash