?
Solved

Saving Form Data to a text file

Posted on 2013-02-04
7
Medium Priority
?
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

762 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