Solved

Saving Form Data to a text file

Posted on 2013-02-04
7
230 Views
Last Modified: 2013-02-12
I need to save form data into a text file but when it gets saved, not all the fields get saved on the text file: (dob, dobmm, gender, address, member, ccnumber, ccmonth, ccyear, duration)

<form method="post" action="regiform.php">

	<p>
		<label>First Name:*</label>
		<input name="name" id= "name" type="text"/>
	</p>

	<p>
		<label>Surname:*</label>
		<input name="surname" id="surname" type="text"/>
	</p>
	
	<p>
		<label>Email:*</label>
		<input name="email" id="email" type="text"/>
	</p>

	<p>
		<label>Date of Birth:</label>
 		<select id="dob">
        <option value="">dd</option>
			<option value="01" >01</option>
			<option value="02" >02</option>
			<option value="03" >03</option>
			<option value="04" >04</option>
			<option value="05" >05</option>
			<option value="06" >06</option>
			<option value="07" >07</option>
			<option value="08" >08</option>
			<option value="09" >09</option>
			<option value="10" >10</option>
			<option value="11" >11</option>
			<option value="12" >12</option>
			<option value="13" >13</option>
			<option value="14" >14</option>
			<option value="15" >15</option>
			<option value="16" >16</option>
			<option value="17" >17</option>
			<option value="18" >18</option>
			<option value="19" >19</option>
			<option value="20" >20</option>
			<option value="21" >21</option>
			<option value="22" >22</option>
			<option value="23" >23</option>
			<option value="24" >24</option>
			<option value="25" >25</option>
			<option value="26" >26</option>
			<option value="27" >27</option>
			<option value="28" >28</option>
			<option value="29" >29</option>
			<option value="30" >30</option>
			<option value="31" >31</option>
      </select>
      /
      <select id="dobmm">
        <option value="">mm</option>
			<option value="01" >01</option>
			<option value="02" >02</option>
			<option value="03" >03</option>
			<option value="04" >04</option>
			<option value="05" >05</option>
			<option value="06" >06</option>
			<option value="07" >07</option>
			<option value="08" >08</option>
			<option value="09" >09</option>
			<option value="10" >10</option>
			<option value="11" >11</option>
			<option value="12" >12</option>
	</select>
  /

		
		<input name="dobyear" id="dobyear" type="text"/>
		<label>Year</label>
</p>

	<p>
		<label>Gender:</label>
		<input name="gender" id= "gender" type= "radio" value= "male"/><span>Male</span>
		<input name="gender" id= "gender" type= "radio" value= "female"/><span>Female</span>
</p>

	<p>
		<label>Address:</label>
		<textarea name="address" id="address" rows="4" cols="20"></textarea>
</p>

	<p>
		<label>Membership Type:*</label>
		<select id="member">
			<option value="">select</option>
			<option value="premium">Premium</option>
			<option value="basic">Basic</option>
			<option value="casual">Casual</option>
		</select>
</p>

	<p>
		<label>Credit Card Number:*</label>
		<input name="ccnumber" id="ccnumber" type="text"/>
</p>

	<p>
		<label>Expiry Date:*</label>
		<select id="ccmonth">
			<option value="">month</option>
			<option value="01" >01</option>
			<option value="02" >02</option>
			<option value="03" >03</option>
			<option value="04" >04</option>
			<option value="05" >05</option>
			<option value="06" >06</option>
			<option value="07" >07</option>
			<option value="08" >08</option>
			<option value="09" >09</option>
			<option value="10" >10</option>
			<option value="11" >11</option>
		</select>
		/
      <select id="ccyear">
        <option value="">year</option>
			<option value="2013" >2013</option>
			<option value="2014" >2014</option>
			<option value="2015" >2015</option>
			<option value="2016" >2016</option>
			<option value="2017" >2017</option>
			<option value="2018" >2018</option>
			<option value="2019" >2019</option>
			<option value="2020" >2020</option>
			<option value="2021" >2021</option>
			<option value="2022" >2022</option>
			<option value="2023" >2023</option>
			<option value="2024" >2024</option>
	</select>
</p>

	<p>
		<label>Duration of Membership:*</label>
		<select id="duration">
			<option value="">select</option>
			<option value="3month">3 month</option>
			<option value="6month">6 month</option>
			<option value="1year">1 year</option>
		</select>
</p>
	<p class="sendbuttom">
		<input type= "submit" id= "send" value= "SEND"></input>
</p>

</form>

Open in new window


<?php 

$name = $_POST['name'];
$surname = $_POST['surname'];
$email = $_POST['email'];

$dob = $_POST['dob'];
$dobmm = $_POST['dobmm'];
$dobyear = $_POST['dobyear'];

$gender = $POST['gender'];
$address = $POST['address'];
$member = $POST['member'];

$ccnumber = $POST['ccnumber'];
$ccmonth = $POST['ccmonth'];
$ccyear = $POST['ccyear'];

$duration = $POST['duration'];



$f = fopen('registrations.txt', 'a');
fwrite($f, "<p>$name</p><hr>");
fwrite($f, "<p>$surname</p>");
fwrite($f, "<p>$email</p>");

fwrite($f, "<p>$dob</p>");
fwrite($f, "<p>$dobmm</p>");
fwrite($f, "<p>$dobyear</p>");

fwrite($f, "<p>$gender</p>");
fwrite($f, "<p>$address</p>");
fwrite($f, "<p>$member</p>");

fwrite($f, "<p>$ccnumber</p>");
fwrite($f, "<p>$ccmonth</p>");
fwrite($f, "<p>$ccyear</p>");

fwrite($f, "<p>$duration</p>");
fclose($f);

?>

Open in new window

0
Comment
Question by:chrissy009
7 Comments
 
LVL 22

Expert Comment

by:plusone3055
Comment Utility
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
Comment Utility
Let me guess... the selects don't get saved... and that would be because things like $_POST['ccyear']  do not exist.  The $_POST variables us the name attribute, and do not even know the id is there.

Cd&
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Try to use "w" switch insteda of "a"

$f = fopen('registrations.txt', 'w');
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
... and Like Cd said - you have to put name attributes on all of the form fields
0
 

Author Comment

by:chrissy009
Comment Utility
I have added name attributes to all the form fields but some fields still doesn´t work: gender, address, member, ccnumber, ccmonth, ccyear, duration
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
You can't have two the same id's on the page like
id= "gender"
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Chnage the ids to name attributes.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now