Hello, New to php
I have a set of checkboxes that I can get to echo, but cannot get to post to upload to an text file.
Any help would be much appreciated.
HTML code
<form name="contactform" method="post" action="email3.php?savedata=1">
<table width="530">
<td width="174"></tr>
<tr>
<td valign="top">
First Name *
</td>
<td width="180" valign="top"><input type="text" name="first_name" maxlength="50" size="30" /></td>
<td width="101" valign="top">Last Name *</td>
<td width="180" valign="top"><input type="text" name="last_name" maxlength="50" size="30" /></td>
</tr>
<tr>
<td><input name="FrameNo" type="text" value="" size="16" maxlength="16" id="FrameNo" />
*</td>
<td height="30"><input type="checkbox" name="firstorder[]" value="8.10" /></td>
<td height="30"><input type="checkbox" name="firstorder[]" value="A8.10" /></td>
<td height="30"><input type="checkbox" name="firstorder[]" value="5.7" /></td>
<td height="30"><input type="checkbox" name="firstorder[]" value="A5.7" /></td>
<td height="30"><input type="checkbox" name="firstorder[]" value="11.14" /></td>
<td height="30"><input type="checkbox" name="firstorder[]" value="4.6" /></td>
<td height="30"><input type="checkbox" name="firstorder[]" value="16.20" /></td>
<td height="30"><input type="checkbox" name="firstorder[]" value="L.Res" /></td>
<td><input type="checkbox" name="firstorder[]" value="H.Res" /></td>
<td> </td>
</tr>
<tr>
<td colspan="4" style="text-align:center">
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</form>
PHP code
<?php
$savedata = $_REQUEST['savedata'];
$fstorder = $_POST['firstorder'];
if(empty($fstorder))
{
echo("Please select a size.");
}
else
{
$N = count($fstorder);
echo("You selected $N size(s): ");
for($i=0; $i < $N; $i++)
{
echo($fstorder[$i] . ", ");
}
}
if ($savedata == 1){
$data .="First Name: ".$_POST['first_name']. PHP_EOL;
$data .="Last Name: ".$_POST['last_name']. PHP_EOL;
$data .="Frame 1: ".$_POST['FrameNo']. PHP_EOL;
//$data .="First Order: ".$_POST['firstorder']. PHP_EOL;
$data .="First Order: ";
$N = count($fstorder);
for($i=0; $i < $N; $i++)
{
$data .=.$fstorder[$i].;
}
$data .=PHP_EOL;
$filename = $_POST['last_name'];
$filename2 = $filename.".";
$target = "upload/";
$target = $target . $filename2.txt;
$fp = fopen($target, "a") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!");
fclose($fp);
echo "Your Form has been Submitted!";
}
?>
Thanks
I have a set of checkboxes that I can get to echo, but cannot get to post to upload to an text file.
Any help would be much appreciated.
HTML code
<form name="contactform" method="post" action="email3.php?savedata=1">
<table width="530">
<td width="174"></tr>
<tr>
<td valign="top">
First Name *
</td>
<td width="180" valign="top"><input type="text" name="first_name" maxlength="50" size="30" /></td>
<td width="101" valign="top">Last Name *</td>
<td width="180" valign="top"><input type="text" name="last_name" maxlength="50" size="30" /></td>
</tr>
<tr>
<td><input name="FrameNo" type="text" value="" size="16" maxlength="16" id="FrameNo" />
*</td>
<td height="30"><input type="checkbox" name="firstorder[]" value="8.10" /></td>
<td height="30"><input type="checkbox" name="firstorder[]" value="A8.10" /></td>
<td height="30"><input type="checkbox" name="firstorder[]" value="5.7" /></td>
<td height="30"><input type="checkbox" name="firstorder[]" value="A5.7" /></td>
<td height="30"><input type="checkbox" name="firstorder[]" value="11.14" /></td>
<td height="30"><input type="checkbox" name="firstorder[]" value="4.6" /></td>
<td height="30"><input type="checkbox" name="firstorder[]" value="16.20" /></td>
<td height="30"><input type="checkbox" name="firstorder[]" value="L.Res" /></td>
<td><input type="checkbox" name="firstorder[]" value="H.Res" /></td>
<td> </td>
</tr>
<tr>
<td colspan="4" style="text-align:center">
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</form>
PHP code
<?php
$savedata = $_REQUEST['savedata'];
$fstorder = $_POST['firstorder'];
if(empty($fstorder))
{
echo("Please select a size.");
}
else
{
$N = count($fstorder);
echo("You selected $N size(s): ");
for($i=0; $i < $N; $i++)
{
echo($fstorder[$i] . ", ");
}
}
if ($savedata == 1){
$data .="First Name: ".$_POST['first_name']. PHP_EOL;
$data .="Last Name: ".$_POST['last_name']. PHP_EOL;
$data .="Frame 1: ".$_POST['FrameNo']. PHP_EOL;
//$data .="First Order: ".$_POST['firstorder']. PHP_EOL;
$data .="First Order: ";
$N = count($fstorder);
for($i=0; $i < $N; $i++)
{
$data .=.$fstorder[$i].;
}
$data .=PHP_EOL;
$filename = $_POST['last_name'];
$filename2 = $filename.".";
$target = "upload/";
$target = $target . $filename2.txt;
$fp = fopen($target, "a") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!");
fclose($fp);
echo "Your Form has been Submitted!";
}
?>
Thanks