Still Having Troubles. Can somebody please debug this?
Posted: Mon Jun 16, 2003 7:22 am
Hey guys,
Once again I am having troubles trying to update my database. I tried all of the suggestions below and none have worked. Can somebody with a spare moment try to get this to work for me? Here's the basic run down. I have a page that displays records in a table. Before each record a chkbox(i) is inserted to keep track of which record to delete/update. But like I said, it won't work. I'm almost 100% sure it has some thing to do with Update statement or how the chkBoxes are being spit out. Here's what I have so far:
[Admin Edit: Added tags]
Any help is greatly appreciated and thanks in advance.
Once again I am having troubles trying to update my database. I tried all of the suggestions below and none have worked. Can somebody with a spare moment try to get this to work for me? Here's the basic run down. I have a page that displays records in a table. Before each record a chkbox(i) is inserted to keep track of which record to delete/update. But like I said, it won't work. I'm almost 100% sure it has some thing to do with Update statement or how the chkBoxes are being spit out. Here's what I have so far:
Code: Select all
<?
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 = '" . $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");
?>Code: Select all
Any help is greatly appreciated and thanks in advance.