Solved

Saving Form Data to a text file

Posted on 2013-02-04
7
232 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
ID: 38852052
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

772 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