[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Saving Form Data to a text file

Posted on 2013-02-04
7
Medium Priority
?
242 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 53

Accepted Solution

by:
COBOLdinosaur earned 1500 total points
ID: 38852079
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
ID: 38852139
Try to use "w" switch insteda of "a"

$f = fopen('registrations.txt', 'w');
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

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

Author Comment

by:chrissy009
ID: 38852292
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
ID: 38852314
You can't have two the same id's on the page like
id= "gender"
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 38852323
Chnage the ids to name attributes.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses
Course of the Month20 days, 14 hours left to enroll

810 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