Form write to a file.
Posted: Tue Jun 16, 2009 2:39 pm
Hi guys, im not so good in programming, can you help me with this, i can sense this would be very simple to some of you. My problem is, i changed the action page from index.php (where this code is present) into a new page which is thankyouform.php. The issue here is, the form doesnt write to the file after i changed the action page. What seems to be the problem. Can someone help me pls. Below is the code.
Code: Select all
<form method="post" action="thankyouform.php">
<table align="center" width="751" bgcolor="#fe7202" border="0">
<tr>
<td width="277" valign="top" align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><strong>Sign up to this site so you can subscribe to our extensive list of financial newsletters and take advantage of our unique offers. </strong></font></td>
<td width="70" height="24" valign="top">
<b><font face="Arial, Helvetica, sans-serif" >Name<br>
<br>
E-mail</font></b></td>
<td width="390" valign="top"><input type="text" name="name" size="40">
<br>
<br>
<input type="text" name="email" size="40"><br>
</td>
</tr>
<tr>
<td align="left"> </td>
<td colspan="2" align="left"> <input type="submit" name="submit" value="Find out now!" />
<?php
if ($_POST['submit'] == "Find out now!") {
$filename = "file.txt";
$ip = $_SERVER['REMOTE_ADDR'];
$content = "\r\n".$_POST['name'].",";
$content .= $_POST['email'].",";
$content .= $_POST['$ip'];
if (!$handle = fopen($filename, "a+<br>")) {
echo 'Cannot open file: ' . $filename;
exit;
}
if (!fwrite($handle, $content)) {
echo 'Cannot write to file: ' . $filename;
exit;
}
echo "<font color='#000000'> Thank You!</font>";
}
?></td>
</tr>
</table>
</form>