Hey guys and gals,
ok, I have a page that uses both location names and location codes. Basically I need to use both so I'm saving the codes to the database and displaying the codes to the user as locations. But for some reason when I try to save the record the location always saves as "GWE" which is the last place. If I put in elseifs instead of ifs it will always choose CBV (the first location). How can I get this to choose the proper location?
<?
include("header.inc");
include("menu.inc");
include("details.inc");
//Post all values into variables from the enterForm.php form
$serial = $_POST['serial'];
$asset = $_POST['asset'];
$name = $_POST['name'];
$location = $_POST['location'];
$po = $_POST['po'];
$doe = date("F j, Y");
$assign = $_POST['assignment'];
$eow = $_POST['eow'];
$opp = $_POST['opp'];
print($location);
//Check to see if the user left the item name blank
if($name!="") {
switch ($location) {
case "Baie Verte":
$location="CBV";
break;
case "Bishop Falls":
$location="CBF";
break;
case "Botwood":
$location="CBT";
break;
case "Buchans":
$location="CBN";
break;
case "Carmenville":
$location="GCE";
break;
case "Centreville":
$location="GCN";
break;
case "Change Islands":
$location="GCI";
break;
case "Fogo Island":
$location="GFO";
break;
case "Gambo":
$location="GDC";
break;
case "Gander":
$location="GGR";
break;
case "Gaultois":
$location="CGA";
break;
case "Glenwood":
$location="GGD";
break;
case "Glovertown":
$location="GGN";
break;
case "Grand Falls":
$location="CGF";
break;
case "Greenspond":
$location="GGP";
break;
case "Harbour Breton":
$location="CHB";
break;
case "Hare Bay":
$location="GHB";
break;
case "Harry's Harbour":
$location="CHH";
break;
case "Hermitage":
$location="CHM";
break;
case "King's Point":
$location="CKP";
break;
case "La Scie":
$location="CLS";
break;
case "Lewisporte":
$location="GLE";
break;
case "Lumsden":
$location="GLN";
break;
case "Musgrave Harbour":
$location="GMH";
break;
case "Norris Arm":
$location="CNA";
break;
case "Point Leamington":
$location="CPL";
break;
case "Robert's Arm":
$location="CRA";
break;
case "Seal Cove":
$location="CSC";
break;
case "Springdale":
$location="CSP";
break;
case "St. Alban's":
$location="CSA";
break;
case "Summerford":
$location="GSD";
break;
case "Twillingate":
$location="GTE";
break;
}
//If fields are left blank, fill them with hyphons
if($serial=="") {
$serial="-";
}
if($asset=="") {
$asset="-";
}
if($description=="") {
$description="-";
}
if($warranty=="") {
$warranty="-";
}
if($assign=="") {
$assign="-";
}
if($opp=="") {
$opp="-";
}
//If the data is not a duplicate, insert it into the database
$query = "INSERT INTO assets SET serialNum = '" . $serial . "', assetNum = '" . $asset . "', itemName = '" . $name . "', location = '" . $location . "', po = '" . $po . "', entryDate = '" . $doe . "', eow = '" . $eow . "', assignment = '" . $assign . "', opp = '" . $opp . "'";
mysql_query($query) or die (mysql_error());;
printf("<TR ALIGN=center><TD><BR>The data has been entered successfully</TD></TR>");
}
//If the user left the item name blank, inform the user it is required to complete this field
elseif($name=="") {
print("<TR ALIGN=center><TD><BR>You must enter a name and location</TD></TR>");
}
print($query);
include("footer.inc");
?>