help a newbie with code pleeeeaaassse!!!
Posted: Tue Jan 27, 2004 9:04 pm
I made this form for users to register for a user name and password. It worked great until I tried to add validation code. As you can tell I am new at this so be patient, please. The form is filled out by the user and then it adds them to the db, mails me and then redirects the user to a thankyou page. Like I said it was working fine. I get an error on the last php script. I have tried moving the code around and still nothing...I m at the end of my rope. Any help you can give I would appreciate. Thanks in advance and here is a copy of my code.
<?php
if ($submit) {
if (!$first||!$last||!$bname||!$baddress||!$telephone||!$email) {
$error = "Sorry! You didn't fill in all the fields!";
}else{
// process form
echo "Thank You!";
}
if (!$submit || $error) {
echo $error;
$db = mysql_connect("localhost", "username","password");
mysql_select_db("mydb",$db);
$sql = "INSERT INTO Customers (first,last,bname,baddress,saddress,telephone,email,acomments,ila,time) VALUES
('$first','$last','$bname','$baddress','$saddress','$telephone','$email','$acomments',curdate(),curtime())";
$result = mysql_query($sql);
mail("rrcole2@shaw.ca","user name and password request",$sql,"From: phpFormGenerator");
header("Refresh: 0;url=http://www.shannonslittlesoapco.com/thnx.htm");
} else{
// display form
?>
<p>
<form method="post" action="<?php echo $PHP_SELF?>">
<table width="75%" border="0" align="center">
<tr>
<td>First name:</td>
<td><input type="Text" name="first" value="<?php echo $first?>"></td>
</tr>
<tr>
<td>Last name:</td>
<td><input type="Text" name="last" value="<?php echo $last ?>"></td>
</tr>
<tr>
<td>business name:</td>
<td><input name="bname" type="text" id="bname2" maxlength="20" value="<?php echo $bname ?>"></td>
</tr>
<tr>
<td>Billing Address:</td>
<td><textarea name="baddress" cols="30" rows="3" id="baddress" accesskey="<?php echo $baddress ?>"></textarea></td>
</tr>
<tr>
<td> Shipping Address:</td>
<td><textarea name="saddress" cols="30" rows="3" id="saddress">same as billing address</textarea></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input name="email" type="text" id="email2" size="20" value="<?php echo $email ?>"></td>
</tr>
<tr>
<td>Telephone Number:</td>
<td><input name="telephone" type="text" id="telephone2" value="<?php echo $telephone ?>"></td>
</tr>
<tr>
<td>Additional Comments:</td>
<td><textarea name="acomments" cols="30" rows="3" id="textarea3"></textarea></td>
</tr>
</table>
<div align="center"><br>
<input type="Submit" name="submit" value="Enter information">
</div>
</form>
<?php
} // end if
?>
<?php
if ($submit) {
if (!$first||!$last||!$bname||!$baddress||!$telephone||!$email) {
$error = "Sorry! You didn't fill in all the fields!";
}else{
// process form
echo "Thank You!";
}
if (!$submit || $error) {
echo $error;
$db = mysql_connect("localhost", "username","password");
mysql_select_db("mydb",$db);
$sql = "INSERT INTO Customers (first,last,bname,baddress,saddress,telephone,email,acomments,ila,time) VALUES
('$first','$last','$bname','$baddress','$saddress','$telephone','$email','$acomments',curdate(),curtime())";
$result = mysql_query($sql);
mail("rrcole2@shaw.ca","user name and password request",$sql,"From: phpFormGenerator");
header("Refresh: 0;url=http://www.shannonslittlesoapco.com/thnx.htm");
} else{
// display form
?>
<p>
<form method="post" action="<?php echo $PHP_SELF?>">
<table width="75%" border="0" align="center">
<tr>
<td>First name:</td>
<td><input type="Text" name="first" value="<?php echo $first?>"></td>
</tr>
<tr>
<td>Last name:</td>
<td><input type="Text" name="last" value="<?php echo $last ?>"></td>
</tr>
<tr>
<td>business name:</td>
<td><input name="bname" type="text" id="bname2" maxlength="20" value="<?php echo $bname ?>"></td>
</tr>
<tr>
<td>Billing Address:</td>
<td><textarea name="baddress" cols="30" rows="3" id="baddress" accesskey="<?php echo $baddress ?>"></textarea></td>
</tr>
<tr>
<td> Shipping Address:</td>
<td><textarea name="saddress" cols="30" rows="3" id="saddress">same as billing address</textarea></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input name="email" type="text" id="email2" size="20" value="<?php echo $email ?>"></td>
</tr>
<tr>
<td>Telephone Number:</td>
<td><input name="telephone" type="text" id="telephone2" value="<?php echo $telephone ?>"></td>
</tr>
<tr>
<td>Additional Comments:</td>
<td><textarea name="acomments" cols="30" rows="3" id="textarea3"></textarea></td>
</tr>
</table>
<div align="center"><br>
<input type="Submit" name="submit" value="Enter information">
</div>
</form>
<?php
} // end if
?>