I have a form im making as part of an assignment at college, however I am having some trouble and im not sure where the error is. There are 4 fields in the form. When its submitted it will error check and display an error message if you forgot to fill something in. My problem is that even if all the fields are filled out then it still takes you to the error message rather than sending the form.
Here is the HTML form code:
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Contact Form</title>
</head>
<body>
<form action="send.php" name="Contact" method="post">
<table border="1" style="border-collapse: collapse" width="66%" id="table1" bordercolor="#808080">
<tr>
<td colspan="2" bgcolor="#6666FF">
<p align="center"><b><u><font face="Verdana" size="2" color="#FFFFFF">
Contact Form</font></u></b></td>
</tr>
<tr>
<td width="13%"><font size="2" face="Verdana">Name:</font></td>
<td width="85%"> <input type="text" name="name" size="33" style="border: 1px solid #C0C0C0"></td>
</tr>
<tr>
<td width="13%"><font size="2" face="Verdana">E-Mail</font></td>
<td width="85%"> <input type="text" name="uemail" size="33" style="border: 1px solid #C0C0C0"></td>
</tr>
<tr>
<td width="13%"><font size="2" face="Verdana">Subject:</font></td>
<td width="85%"> <select size="1" name="subject" style="border: 1px solid #C0C0C0">
<option selected>Select Subject</option>
<option value="Comments?">Comments?</option>
<option value="Misc.?">Misc.?</option>
<option value="Website Problems?">Website Problems?</option>
<option value="Questions?">Questions?</option>
</select></td>
</tr>
<tr>
<td width="13%" valign="top"><font size="2" face="Verdana">Message:</font></td>
<td width="85%"> <textarea rows="12" name="message" cols="46" style="border: 1px solid
#C0C0C0"></textarea></td>
</tr>
<tr>
<td colspan="2">
<p align="center">
<input type="submit" value="Send E-Mail" name="send" style="border: 1px solid #000000">
<input type="reset" value="Clear Form" name="clear" style="border: 1px solid #000000"></td>
</tr>
<tr>
<td colspan="2" bgcolor="#6666FF"> </td>
</tr>
</table>
</form>
</body>
</html>
And here is the PHP Code:
Any help on what im doing wrong is appreciated..
Here is the HTML form code:
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Contact Form</title>
</head>
<body>
<form action="send.php" name="Contact" method="post">
<table border="1" style="border-collapse: collapse" width="66%" id="table1" bordercolor="#808080">
<tr>
<td colspan="2" bgcolor="#6666FF">
<p align="center"><b><u><font face="Verdana" size="2" color="#FFFFFF">
Contact Form</font></u></b></td>
</tr>
<tr>
<td width="13%"><font size="2" face="Verdana">Name:</font></td>
<td width="85%"> <input type="text" name="name" size="33" style="border: 1px solid #C0C0C0"></td>
</tr>
<tr>
<td width="13%"><font size="2" face="Verdana">E-Mail</font></td>
<td width="85%"> <input type="text" name="uemail" size="33" style="border: 1px solid #C0C0C0"></td>
</tr>
<tr>
<td width="13%"><font size="2" face="Verdana">Subject:</font></td>
<td width="85%"> <select size="1" name="subject" style="border: 1px solid #C0C0C0">
<option selected>Select Subject</option>
<option value="Comments?">Comments?</option>
<option value="Misc.?">Misc.?</option>
<option value="Website Problems?">Website Problems?</option>
<option value="Questions?">Questions?</option>
</select></td>
</tr>
<tr>
<td width="13%" valign="top"><font size="2" face="Verdana">Message:</font></td>
<td width="85%"> <textarea rows="12" name="message" cols="46" style="border: 1px solid
#C0C0C0"></textarea></td>
</tr>
<tr>
<td colspan="2">
<p align="center">
<input type="submit" value="Send E-Mail" name="send" style="border: 1px solid #000000">
<input type="reset" value="Clear Form" name="clear" style="border: 1px solid #000000"></td>
</tr>
<tr>
<td colspan="2" bgcolor="#6666FF"> </td>
</tr>
</table>
</form>
</body>
</html>
And here is the PHP Code:
PHP Code:
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<center>
<br>
<br>
<br>
<?php
$message = "Thank you for using my online form.\n";
// Contact Name
if ($name)
{
$user = "Name - $name";
$message .= "$user\n";
}
else
{
$error .= "You did not enter your name<br>\n";
}
// Email Address
if ($uemail)
{
$umail = "Email - $uemail";
$message .= "$umail\n";
}
else
{
$error .= "You did not enter your email address<br>\n";
}
// Message Subject
if ($subject)
{
$usubject = "Subject - $subject";
$message .= "$usubject\n" ;
}
else
{
$error .= "You did not select a subject<br>\n";
}
// Contact Message
if ($message)
{
$comments = "Message - $message";
$message .= "$comments\n";
}
else
{
$error .= "You did not enter any comments<br>\n";
}
// If there is no error this part of the code sends the email
if ($error == "")
{
echo "Thank you for using my online form.
<br>
<br>You will be emailed a copy of your message.<br><br>
<br>Please use your browsers back buttom to return to the previous page.
<br><br>Thank you.";
// This Part of the code sends the email to the user
mail("$uemail", "Email Challenge", $message, "From: Ronnie Williams <[email protected]>");
// This part of the code sends the email to the owner
mail("[email protected]", "Email Challenge", $message, "From: $uemail");
// If there is an error this part of the code displays what the error is
}
else
{
print "Sorry, but the form cannot be sent until you correct the following errors:<br>\n";
print "$error<br>\n";
print "<br>\n";
print "<br>\n";
print "Please use your \"Back\" button to return to the form to correct the omissions. Thank you.<br>\n";
}
?>
</center>
</BODY>
</HTML>
Any help on what im doing wrong is appreciated..
Comment