PDA

View Full Version : Help me with my first html form :-)



Roar!
01-30-2007, 12:49 AM
I've been trying and I think I'm just about there. Except I'm stuck.

<
<form name="carpool" action="submit.php" method="post">

Check the days that you are able to drive <b>TO</b> rowing.<p>
<LABEL><INPUT TYPE="checkbox" NAME="day" VALUE="Monday"> Monday</LABEL>
<LABEL><INPUT TYPE="checkbox" NAME="day" VALUE="Tuesday"> Tuesday</LABEL>
<LABEL><INPUT TYPE="checkbox" NAME="day" VALUE="Thursday">Thursday</LABEL>
<LABEL><INPUT TYPE="checkbox" NAME="day" VALUE="Friday">Friday</LABEL>
<LABEL><INPUT TYPE="checkbox" NAME="day" VALUE="Saturday">Saturday</LABEL>
</p>
Check the days that you are able to drive <b>FROM</b> rowing.<p>
<LABEL><INPUT TYPE="checkbox" NAME="day" VALUE="Monday"> Monday</LABEL>
<LABEL><INPUT TYPE="checkbox" NAME="day" VALUE="Tuesday"> Tuesday</LABEL>
<LABEL><INPUT TYPE="checkbox" NAME="day" VALUE="Thursday">Thursday</LABEL>
<LABEL><INPUT TYPE="checkbox" NAME="day" VALUE="Friday">Friday</LABEL>
<LABEL><INPUT TYPE="checkbox" NAME="day" VALUE="Saturday">Saturday</LABEL>
</p>
<input type="submit" name="submit" value="el submito" />
There is my form. When I click the submit button, It wants to download my submit.php file. Not what I want. I just watn to save the results to a text file on my computer.
Here's my php file:

<?php
$day = $_POST['day'];

if(!$day)
{
echo "Please submit some days";
exit;
}
else
{
$filename = "carpool.txt";
$content = "$day\n";
$fp = fopen($filename, "a");
$fw = fwrite( $fp, $content );
fclose( $fp );

if(!$fw) echo "You made a mistake, try again or ill kill you or something.";
else echo "Successfully submitted.";
}
?>


I've also got a text file named carpool.txt



Thanks for reading and extra thanks if you help. :)

~~smart~fool~~
01-30-2007, 06:17 PM
Try this

<?
$filename = 'carpool.txt';
$day = $_POST['day'];

if (is_writable($filename))
{
if (!$handle = fopen($filename, 'a'))
{
exit;
}
if (fwrite($handle, $day) === FALSE)
{
exit;
}
fclose($handle);
}
?>

Roar!
01-30-2007, 10:14 PM
I used that php scripty but it did the same thing as the last. I'l open the HTML, click on some options, and push the submit button and it asks me if I wan't to download my php file. Not exactly what I'm going for.