Still Having Troubles. Can somebody please debug this?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Keanman
Forum Newbie
Posts: 18
Joined: Fri Jun 13, 2003 3:19 pm
Contact:

Still Having Troubles. Can somebody please debug this?

Post by Keanman »

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:

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");
?>
[Admin Edit: Added tags]

Any help is greatly appreciated and thanks in advance.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

It would make it a bit easier for us to help you debug if you posted any error messages you receive and/or what happens/doesn't happen that shouldn't/should.

Mac
Keanman
Forum Newbie
Posts: 18
Joined: Fri Jun 13, 2003 3:19 pm
Contact:

Still Having Troubles. Can somebody please debug this?

Post by Keanman »

Ok, no errors are coming up at all and the unix error log comes up clean too. Maybe I can break the problem down a little more.

The info is taken from the user via text boxes and stored into variables. I have printed them to make sure they work. I have used a checkbox array along with a serial array to make the program know which record to delete/update (Mind you the delete button works fine so I don't think there is a prolem with my variables). Then the variables should be going into their corresponding fields through SET but the new info will not be updated to the database. After clicking update the database gets refreshed and the old data is still there.

If you guys need it broken down more than that let me know.
Keanman
Forum Newbie
Posts: 18
Joined: Fri Jun 13, 2003 3:19 pm
Contact:

Post by Keanman »

I'm not 100% sure. But the search, insert and delete pages work so I'm assuming that it does start at 0.

I'm also not 100% sure what the problem is but I think it's related to the UPDATE statement.
Post Reply