Simple insert problem. I think.
Posted: Fri Aug 01, 2003 9:29 am
Hey guys and gals,
I just recoded a page so that locations are now changed to three letter codes. This takes care of my concatenation problem. But now for some reason it won't insert data. Which it was doing a day ago. I've printed $query and all the variables are working fine. The only problem I can see with the page is that the close php tag appears in orange, not purple as it's supposed to. But when I make it purple and save it. Then reload. It's orange again. Here's my code:
I just recoded a page so that locations are now changed to three letter codes. This takes care of my concatenation problem. But now for some reason it won't insert data. Which it was doing a day ago. I've printed $query and all the variables are working fine. The only problem I can see with the page is that the close php tag appears in orange, not purple as it's supposed to. But when I make it purple and save it. Then reload. It's orange again. Here's my code:
Code: Select all
<?
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'];
//Check to see if the user left the item name blank
if($name!="") {
if($location = "Baie Verte") {
$location = "CBV";
}
if($location = "Bishop Falls") {
$location = "CBF";
}
if($location = "Botwood") {
$location = "CBT";
}
if($location = "Buchans") {
$location = "CBN";
}
if($location = "Carmanville") {
$location = "GCE";
}
if($location = "Centreville") {
$location = "GCN";
}
if($location = "Change Islands") {
$location = "GCI";
}
if($location = "Fogo Island") {
$location = "GFO";
}
if($location = "Gambo") {
$location = "GDC";
}
if($location = "Gander") {
$location = "GGR";
}
if($location = "Gaultois") {
$location = "CGA";
}
if($location = "Glenwood") {
$location = "GGD";
}
if($location = "Glovertown") {
$location = "GGN";
}
if($location = "Grand Falls") {
$location = "CGF";
}
if($location = "Greenspond") {
$location = "GGP";
}
if($location = "Harbour Breton") {
$location = "CHB";
}
if($location = "Hare Bay") {
$location = "GHB";
}
if($location = "Harry's Harbour") {
$location = "CHH";
}
if($location = "Hermitage") {
$location = "CHM";
}
if($location = "King's Point") {
$location = "CKP";
}
if($location = "La Scie") {
$location = "CLS";
}
if($location = "Lewisporte") {
$location = "GLE";
}
if($location = "Lumsden") {
$location = "GLN";
}
if($location = "Musgrave Harbour") {
$location = "GMH";
}
if($location = "Norris Arm") {
$location = "CNA";
}
if($location = "Point Leamington") {
$location = "CPL";
}
if($location = "Robert's Arm") {
$location = "CRA";
}
if($location = "Seal Cove") {
$location = "CSC";
}
if($location = "Springdale") {
$location = "CSP";
}
if($location = "St. Alban's") {
$location = "CSA";
}
if($location = "Summerford") {
$location = "GSD";
}
if($location = "Twillingate") {
$location = "GTE";
}
if($location = "Wesleyville") {
$location = "GWE";
}
//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="-";
}
$query="SELECT * FROM assets";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$serials=mysql_result($result,$i,"serialNum");
$assets=mysql_result($result,$i,"assetNum");
//Check if the data entered is a duplicate
if($serial==$serials) {
$serialFound="True";
printf("<TR ALIGN=center><TD><BR>The serial number entered already exists</TR>");
}
if($asset==$assets) {
$assetFound="True";
printf("<TR ALIGN=center><TD><BR>The asset number entered already exists</TR>");
}
++$i;
}
//If the data is not a duplicate, insert it into the database
If($serialFound!="True" AND $assetFound!="True") {
$query = "INSERT INTO assets SET serialNum=" . $serial . ",assetNum=" . $asset . ",itemName=" . $name . ",location=" . $location . ",po=" . $po . ",entryDate=" . $doe . ",eow=" . $eow . ",assingment=" . $assign . ",opp=" . $opp;
mysql_query($query);
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=="") {
printf("<TR ALIGN=center><TD><BR>You must enter a name and location</TD></TR>");
}
include("footer.inc");
?>