Hi
I’m trying to get this script to work, it almost works but doesn’t update ALL the fields after you click submit. Two fields don’t display at all (the ones that don’t update) . One field isn’t suppose to update but should display i.e. record_number, the other field i.e. Avalibity, doesn’t display or update (it suppose to update).
Here is the first page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>
<style type="text/css">
body {
margin:50px 0px; padding:0px;
text-align:center;
font:13px Tahoma,Geneva,sans-serif
}
#content {
width:1000px;
margin:0px auto;
text-align:left;
padding:15px;
border:1px dashed #333;
background-color:#eee;
}
</style>
<link rel="icon" href="http://www.mysite.com/favicon.ico" type="image/vnd.microsoft.icon" />
</head>
<body>
<div id='content'><h3><center>Update Product Infomation</center></h3>
<?php
// connect to the database
mysql_connect(localhost,username,password);
// select the database
mysql_select_db(db_name) or die("Unable to select database");
// run the query and put the results in an array variable called $result
$result = mysql_query("SELECT * FROM Products ORDER BY 'record_number', 'Product_Manu_URL', 'manufactures_product_code', 'Avalibity'");
// find out how many records there are to update
$size = count($_POST['record_number']);
// start a counter in order to number the input fields for each record
$i = 0;
print "<table width='100%' border='0' cellspacing='1' cellpadding='0'><tr><td>";
// open a form
print "<form name='namestoupdate' method='post' action='update.php'>
<table width='100%' border='0' cellspacing='1' cellpadding='1'><tr>
<td align='center'><strong>Record Number</strong></td>
<td align='center'><strong>Manufactures Product Code</strong></td>
<td align='center'><strong>Product Manu URL</strong></td>
<td align='center'><strong>Avalibity</strong></td>
</tr>\
";
// start a loop to print all of the courses with their book information
// the mysql_fetch_array function puts each record into an array. each time it is called, it moves the array counter up until there are no more records left
while ($Update = mysql_fetch_array($result)) {
print "</tr>\
";
// assuming you have three important columns (the index (id), the course name (course), and the book info (bookinfo))
// start displaying the info; the most important part is to make the name an array (notice bookinfo[$i])
print "<td align='center'><p>{$Update['record_number']}</p></td>\
";
print "<td align='center'><input type='text' name='manufactures_product_code[$i]' value='{$Update['manufactures_product_code']}' /></td>";
print "<td align='center'><input type='text' size='40' name='Product_Manu_URL[$i]' value='{$Update['Product_Manu_URL']}' /></td>\
";
print "<td align='center'><input type='text' size='40' name='Avalibity[$i]' value='{$Update['Avalibity']}' /></td>\
";
print "</tr>\
";
// add 1 to the count, close the loop, close the form, and the mysql connection
++$i;
}
print "<tr>
<td colspan='4' align='center'><input type='submit' value='submit' />";
print "</td>
</tr>
</table>
</td>
</tr>
</form>
</table>";
mysql_close();
?><br /><br /><div></body>
</html>
here is the 2nd page i.e. update.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>
<style type="text/css">
body {
margin:50px 0px; padding:0px;
text-align:center;
font:13px Tahoma,Geneva,sans-serif
}
#content {
width:1000px;
margin:0px auto;
text-align:left;
padding:15px;
border:1px dashed #333;
background-color:#eee;
}
</style>
<link rel="icon" href="http://www.mysite.com/favicon.ico" type="image/vnd.microsoft.icon" />
</head>
<body>
<div id='content'><h3><center>Success! </center></h3>
<table width='100%' border='0' cellspacing='1' cellpadding='0'><tr><td>
<table width='100%' border='0' cellspacing='1' cellpadding='1'>
<tr>
<td align='center'><strong>Record Number</strong></td>
<td align='center'><strong>Manufactures Product Code</strong></td>
<td align='center'><strong>Product Manu URL</strong></td>
<td align='center'><strong>Avalibity</strong></td>
</tr>
<?php
// connect to the database and select the correct database
mysql_connect(localhost,username,password);
mysql_select_db(db_name) or die("Unable to select database");
// find out how many records there are to update
$size = count($_POST['Avalibity']);
// start a loop in order to update each record
$i = 0;
while ($i < $size) {
// define each variable
$Product_Manu_URL = $_POST['Product_Manu_URL'][$i];
$Record_Number = $_POST['record_number'][$i];
$manufactures_product_code = $_POST['manufactures_product_code'][$i];
$Avalibity = $_POST['Avalibityl'][$i];
// do the update and print out some info just to provide some visual feedback
$query = "UPDATE `Products` SET `Avalibity` = '$Avalibity', `Product_Manu_URL` = '$Product_Manu_URL', `manufactures_product_code` = '$manufactures_product_code' WHERE `record_number` = '$Record_Number' LIMIT 1";
mysql_query($query) or die ("Error in query: $query");
print "
</tr>
<td align='left'><p>$Record_Number</p></td>
<td align='left'>$manufactures_product_code</td>
<td align='left'>$Product_Manu_URL</td>
<td align='left'>$Avalibity</td>
</tr>
";
++$i;
}
mysql_close();
?>
<tr>
<td colspan='4' align='center'>
</td>
</tr>
</table>
</td>
</tr>
</table></div></body></html>
It works very well except I need it to be able to update more fields.
Thanks