Jump to content

Recommended Posts

I am trying to get form data go to a txt file when the submit button is hit..

Unfortunately the person that gave me the script to mess with won't around for a couple weeks..  I am just starting to get into php, so any help would be appreciated..

 

http://www.cloudswalk.com/oldies/requests/14kreq2.php

 

is where I have it..

The code is :

 

<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

$songtitle = $_POST['songtitle'] ;

$artist = $_POST['artist'] ;

$yourname = $_POST['yourname'] ;

$dedication = $_POST['dedication'] ;

$f=fopen("RequestList.txt","a");

fwrite($f,"$songtitle,$artist,$yourname,$dedication\r\n");

fclose($f);

}

?>

 

<center>

          <font face="Verdana" color=03045f>

<table width="450px" border="3" bordercolor="#03045f" cellpadding="10">

<tr>

<td>

<form action="RequestList.txt" method="POST" name="inputform" id="inputform">

<b>Song Title:</b><br />

<input type="text" size="30" name="songtitle" />

<br />

<b>Artist(s):</b><br />

<input type="text" size="30" name="artist" />

<br />

<b>Your Name:</b><br />

<input type="text" size="30" name="yourname" />

<br />

<b>Dedication:</b><br />

<textarea cols="25" name="comments" rows="5">

</textarea>

<br>

<input type="submit" name="submit" value="save" />

</form>

<br>

</td>

</tr>

</table>

</center>

 

 

Thank you

Ellen

Link to comment
https://forums.phpfreaks.com/topic/167410-solved-form-info-to-text/
Share on other sites

<?php 
if (isset($_POST['artist']) || isset($_POST['songtitle']) || isset($_POST['yourname'])) { 
$songtitle = $_POST['songtitle'] ; 
$artist = $_POST['artist'] ; 
$yourname = $_POST['yourname'] ; 
$dedication = $_POST['dedication'] ; 
$f=fopen("RequestList.txt","a"); 
fwrite($f,"".$songtitle.",".$artist.",".$yourname.",".$dedication."\r\n"); 
fclose($f); 
} 
?>

<center>
          <font face="Verdana" color=03045f>
<table width="450px" border="3" bordercolor="#03045f" cellpadding="10">
<tr>
<td>
<form action="RequestList.txt" method="POST" name="inputform" id="inputform">
<b>Song Title:</b><br />
<input type="text" size="30" name="songtitle" />
<br /> 
<b>Artist(s):</b><br />
<input type="text" size="30" name="artist" />
<br />
<b>Your Name:</b><br />
<input type="text" size="30" name="yourname" />
<br />
<b>Dedication:</b><br />
<textarea cols="25" name="comments" rows="5">
</textarea>
<br>
<input type="submit" name="submit" value="save" />
</form>
<br>
</td>
</tr>
</table>
</center>

The problem in the OP script (other than using deprecated stuff, but they still work), is

 

a) your form action points to your text file.  Change it to "" or name of the script (so it points to the script)

b) you are using $_POST['description'] for your text area but you named your text area 'comments' so that value will not be written to your file unless you change that.

Sorry my bad, its been a log day..

Here it is:

 

 

 

 

<?php

$saving = $_REQUEST['saving'];

if ($saving == 1){

$songtitle = $_POST['songtitle'] ;

$artist = $_POST['artist'] ;

$yourname = $_POST['yourname'] ;

$dedication = $_POST['dedication'] ;

$f=fopen("ReqList.txt","a");

fwrite($f,"".$songtitle.",".$artist.",".$yourname.",".$dedication."\r\n"); 

fclose($f);

}

?>

 

<center>

          <font face="Verdana" color=03045f>

<table width="450px" border="3" bordercolor="#03045f" cellpadding="10">

<tr>

<td><center>

<form action="14kreq2.php" method="POST" name="inputform" id="inputform">

<b>Song Title:</b><br />

<input type="text" size="30" name="songtitle" />

<br />

<b>Artist(s):</b><br />

<input type="text" size="30" name="artist" />

<br />

<b>Your Name:</b><br />

<input type="text" size="30" name="yourname" />

<br />

<b>Dedication:</b><br />

<textarea cols="25" name="dedication" rows="5">

</textarea>

<br>

<input type="submit" name="submit" value="save" />

</form></center>

<br>

</td>

</tr>

</table>

</center>

 

<?php
if (isset($_POST['submit']){
$songtitle = $_POST['songtitle'] ;
$artist = $_POST['artist'] ;
$yourname = $_POST['yourname'] ;
$dedication = $_POST['dedication'] ;
$f=fopen("ReqList.txt","a");
fwrite($f,"".$songtitle.",".$artist.",".$yourname.",".$dedication."\r\n"); 
fclose($f);
}
?>

<center>
          <font face="Verdana" color=03045f>
<table width="450px" border="3" bordercolor="#03045f" cellpadding="10">
<tr>
<td><center>
<form action="" method="POST" name="inputform" id="inputform">
<b>Song Title:</b><br />
<input type="text" size="30" name="songtitle" />
<br />
<b>Artist(s):</b><br />
<input type="text" size="30" name="artist" />
<br />
<b>Your Name:</b><br />
<input type="text" size="30" name="yourname" />
<br />
<b>Dedication:</b><br />
<textarea cols="25" name="dedication" rows="5">
</textarea>
<br>
<input type="submit" name="submit" value="save" />
</form></center>
<br>
</td>
</tr>
</table>
</center>

okay, so you've made other changes to your script, in addition to the ones suggested.  You are now saving based on $_REQUEST['saving'] being 1.  I do not see anywhere in your script that sets that to 1. As in, I do not see any elements in your form called 'saving'.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.