Hours and hours of experimenting have led me to this point.
I am trying to do sales tax calculations for a final value based upon the City selected from a MySQL table drop down list.
However, it has some unique requirements (see the if-else options in the code below).
There are over 1,500 entries in the table, and whichever City is selected, I also have to associate the taxrate (AND the County to the City selected as it may need be used in the final mix). And then there is the out-of-state checkbox option in the same form (unless there is a nifty way to use TWO separate forms on the same page?).
I'm also hung up on how to yield an error message if a City has not been selected (and) the checkbox not checked. If there are no errors, then I need to go to the 'nextpage.php' file.
No pretty HTML layout here...that will come later when the darn thing gets working.
Can anyone help find the final solutions? Thanks much.
<?php
//
// --->NEED ERROR MESSAGE CODE IF NO SHIP-TO CITY OR OUT-OF-STATE CHECKBOX IS UNCHECKED IS SELECTED!!!
// ....IF NO ERRORS, TO GO TO: nextpage.php
$error = "";
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
if (((isset($HTTP_POST_VARS["city"])) && ($HTTP_POST_VARS["city"] == "--Select SHIP-TO City--")) &&
((isset($HTTP_POST_VARS["outofstate"])) && ($HTTP_POST_VARS["outofstate"] == "unchecked"))) {
$error .= "You must select a city or out-of-state.<br>";
//} else {
// HOW TO GO TO nextpage.php IF NO ERRORS???
//}
}
}
?>
<html>
<head>
<title>Tax</title>
</head>
<body>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<?php
$hostname = "localhost";
$database = "taxdb";
$username = "me";
$password = "";
$dbcnx = mysql_connect($hostname, $username, $password) or die(mysql_error());
$taxcity = " ";
$taxrate = " ";
$taxcounty = " ";
$outofstate = " ";
mysql_select_db($database, $dbcnx);
$query = "SELECT * FROM salestaxtable";
$list = mysql_query($query, $dbcnx) or die(mysql_error());
?>
MY STATE CUSTOMER:<br>
Please choose SHIP-TO DESTINATION City<br>
<SELECT NAME="city" size="1">
<OPTION SELECTED>--Select SHIP-TO City--
<?php
while ($row = mysql_fetch_assoc($list)) {
$taxcity=$row['taxcity'];
$taxrate=$row['taxrate'];
$taxcounty=$row['taxcounty'];
?>
<OPTION VALUE="<?php echo $taxcity?></OPTION>
<?php
}
?>
</SELECT>
<br><br>
PLEASE CHECK THIS BOX IF YOU ARE AN OUT-OF-STATE CUSTOMER<br>
<input name="outofstate" type="checkbox"> OUT-OF-STATE CUSTOMER<br>
<?php
// Tax Area Rate Configurations
if ($taxcity == "mycity") {
$taxrate == "$taxrate";
} else {
if ($taxcity != $mycity && $taxcounty == "mycounty") {
$taxrate == ".08";
} else {
if ($taxcity != $mycity && $taxcounty != "mycounty") {
$taxrate == ".075";
} else {
if ($outofstate == "checked") {
$taxrate == ".00";
}
?>
<!-- taxrate ($taxrate) MUST be the taxrate for the Selected City based upon the if-else config above -->
echo "<input type=\"hidden\" name=\"taxrate\" value=\"<?php echo $taxrate?>\">";
<input type="hidden" name="MM_insert" value="form1">
<br>
<INPUT name="submit" type="submit" class=submitbutton value="Next Page">
<INPUT name="reset" type="reset" class=resetbutton value="Reset Form">
</form>
</body>
</html>
<?php
?>
😕