Forum Moderators: coopster

Message Too Old, No Replies

Add data from PHP form to a TEXT *.txt file

Add data from PHP form to a TEXT *.txt file

         

fast4u

9:18 pm on Apr 4, 2007 (gmt 0)

10+ Year Member



Hello got another question,

I have a form shown below:


<form name="form1" method="post" action="">
<label>URL Title
<input type="text" name="textfield">
</label>
<p>
<label>URL[starting with http://]
<input type="text" name="textfield2">
</label>
</p>
<p>
<label>Where to add?
<select name="select">
<option selected>pick one</option>
<option>a</option>
<option>b</option>
<option>c</option>
<option>d</option>
<option>e</option>
<option>f</option>
<option>g</option>
<option>h</option>
<option>i</option>
<option>j</option>
<option>k</option>
<option>l</option>
<option>m</option>
<option>n</option>
<option>o</option>
<option>p</option>
<option>q</option>
<option>r</option>
<option>s</option>
<option>t</option>
<option>u</option>
<option>v</option>
<option>w</option>
<option>x</option>
<option>y</option>
<option>z</option>
</select>
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Add a link">
</label>
</p>
</form>

I would like to know if there is way I can make this form work that way that when I everything is selected and I click submit button, it will write the data in certain way in a particular .txt file, and the way the particular file will be selected is from the pulldown menu.

Thank you,

fast4u

phparion

11:32 am on Apr 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



if I am reading you correctly then this code should help you...

$myFile = $_REQUEST['select']; // selected dropdown value is the file name

$fh = fopen($myFile, 'w') or die("can't open file");

// now fetch each form variable and write it

fwrite($fh, $_REQUEST['form_field_name']."\n");

fclose($fh); //close the file after writing is completed