Hey guys,
Like a lot of other people on this forum I'm having some trouble with an update page.
To catch up on what the pages does. It uses a loop to display all the records in a database, puts a check box next to each record (to distinguish which record to update) and has text boxes at the bottom for inputting updated data. The info goes into the variables fine but for some reason it will not update the database. Here's what I've tried:
single quotes
double quotes
slashes
basic screwing around
I think the problem lies in one of these two lines:
$query = "UPDATE assets SET serialNum = " . $serial . ", assetNum = " . $asset . ", itemName = " . $name . ", location = " . $location . ", description = " . $description . ", warranty = " . $warranty . " WHERE serialNum LIKE " . $serial[$i];
or
printf("<TR ALIGN=CENTER><TD><input type=\"checkbox\" name=\"chkBox[$i]\"><input type=\"hidden\" name=\"serial[$i]\" value=\"$serials\"><TD>$name</TD></TD><TD>$serials</TD><TD>$asset</TD><TD>$location</TD><TD>$description</TD><TD>$doe</TD><TD>$warranty</TD></TR>");
Here's the whole code:
<?
include("header.inc");
include("details.inc");
?>
<H2>Update a Record</H2><P><HR><P>
<A HREF="enterForm.php">Enter a Record</A>
<A HREF="searchForm.php">Search Database</A>
<A HREF="userForm.php">Create a New User</A><P><HR></CENTER><P>
<form name="frmCheck" method=post action="<?php echo $PHP_SELF?>">
<?
if(isset($POST['btnUpdate'])) {
$asset = $POST['asset'];
$name = $POST['name'];
$location = $POST['location'];
$description = $POST['description'];
$warranty = $POST['warranty'];
$serial = $POST['serial'];
$checkbox = $POST['chkBox'];
for($i=0;$i < count($serial);$i++) {
if($checkbox[$i]=="on") {
$query = "UPDATE assets SET serialNum = " . $serial . ", assetNum = " . $asset . ", itemName = " . $name . ", location = " . $location . ", description = " . $description . ", warranty = " . $warranty . " WHERE serialNum LIKE" . $serial[$i];
mysql_query($query) or die (mysql_error());
}
}
}
include("title.inc");
$query="SELECT * FROM assets ORDER BY location ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$serials=mysql_result($result,$i,"serialNum");
$asset=mysql_result($result,$i,"assetNum");
$name=mysql_result($result,$i,"itemName");
$location=mysql_result($result,$i,"location");
$description=mysql_result($result,$i,"description");
$doe=mysql_result($result,$i,"entryDate");
$warranty=mysql_result($result,$i,"warranty");
printf("<TR ALIGN=CENTER><TD><input type=\"checkbox\" name=\"chkBox[$i]\"><input type=\"hidden\" name=\"serial[$i]\" value=\"$serials\"><TD>$name</TD></TD><TD>$serials</TD><TD>$asset</TD><TD>$location</TD><TD>$description</TD><TD>$doe</TD><TD>$warranty</TD></TR>");
++$i;
}
?>
</TABLE>
<P>
<TABLE BORDER=1 WIDTH=40% ALIGN="CENTER">
<TR ALIGN=CENTER>
<TD><B>Item Name</B></TD><TD><Input type="text" name="name" size="20"></TD>
</TR>
<TR ALIGN=CENTER>
<TD><B>Serial Number</B></TD><TD><Input type="text" name="serial" size="20"></TD>
</TR>
<TR ALIGN=CENTER>
<TD><B>Asset Number</B></TD><TD><Input type="text" name="asset" size="20"></TD>
</TR>
<TR ALIGN=CENTER>
<TD><B>Location</B></TD><TD><Select name="location" value="location">
<OPTION>
<OPTION>Baie Verte
<OPTION>Botwood
<OPTION>Bishop Falls
<OPTION>Buchans
<OPTION>Carmanville
<OPTION>Centreville
<OPTION>Change Islands
<OPTION>Fogo Island
<OPTION>Gambo
<OPTION>Gander
<OPTION>Gaultois
<OPTION>Glenwood
<OPTION>Glovertown
<OPTION>Grand Falls
<OPTION>Greenspond
<OPTION>Harbour Breton
<OPTION>Hare Bay
<OPTION>Harry's Harbour
<OPTION>Hermitage
<OPTION>King's Point
<OPTION>La Scie
<OPTION>Lewisporte
<OPTION>Lumsden
<OPTION>Musgrave Harbour
<OPTION>Norris Arm
<OPTION>Point Leamington
<OPTION>Robert's Arm
<OPTION>Seal Cove
<OPTION>Springdale
<OPTION>St. Alban's
<OPTION>Summerford
<OPTION>Twillingate
<OPTION>Wesleyville
</SELECT></TD>
</TR>
<TR ALIGN=CENTER>
<TD><B>Description</B></TD><TD><Input type="text" name="description" size="20"></TD>
</TR>
<TR ALIGN=CENTER>
<TD><B>Warranty</B></TD><TD><Input type="text" name="warranty" size="20"></TD>
</TR>
</TABLE>
<BR><CENTER>
<input type="Submit" name="btnUpdate" Value="Update Record">
<input type="Reset" name="Reset">
</FORM></CENTER>
<?
include("footer.inc");
?>
Any helps is greatly appreciated and thanks in advance.
Rod