Hi,
I’m hoping someone can help me with a problem I’m having. I’ve looked at a couple of code examples here but I’m having no luck getting this form to Update.
What I need to do is make a form that shows all the plants in my database and all their prices on one page or in one form, make changes to all the prices and then click update to update all records. I have the items showing but cannot get them to update. Here is my code perhaps some of you wizards out there can see where I’ve screwed up. Thanks a bunch.
PAGE CODE:
[code=php]
<?php require_once(‘../Connections/conn_mill.php’); ?>
<?php
mysql_select_db($database_conn_mill, $conn_mill);
$query_rsHours = “SELECT * FROM hours”;
$rsHours = mysql_query($query_rsHours, $conn_mill) or die(mysql_error());
$row_rsHours = mysql_fetch_assoc($rsHours);
$totalRows_rsHours = mysql_num_rows($rsHours);
mysql_select_db($database_conn_mill, $conn_mill);
$query_rsPot = “SELECT * FROM price”;
$rsPot = mysql_query($query_rsPot, $conn_mill) or die(mysql_error());
$row_rsPot = mysql_fetch_assoc($rsPot);
$totalRows_rsPot = mysql_num_rows($rsPot);
if ((isset($_POST[“Update”])) && ($_POST[“Update”] == “form1”)) {
for ($i = 0; $i < count($_POST[‘hiddenID’]); $i++)
{
$updateSQL = sprintf(“UPDATE price SET Price='”.$_POST[‘Price’].”‘ WHERE HiddenID='”.$_POST[‘ID’].”‘ “);
mysql_select_db($database_conn_mill, $conn_mill);
$Result1 = mysql_query($updateSQL, $conn_mill) or die(mysql_error());
}
}
?>
The Form
[code=php]
<h2>Update Pricing and Pot Size</h2>
<form name=”form1″ method=”POST”>
<table width=”465″ border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”27%”>Plant Name: </td>
<td width=”19%”>Potsize:</td>
<td width=”21%”><div align=”center”>Price:</div></td>
<td width=”33%”><div align=”center”>Stock Availability:</div></td>
</tr>
<?php do { ?>
<tr align=”left”>
<td><span class=”style9″>
<input name=”HiddenID” type=”hidden” id=”HiddenID” value=”<?php echo $row_rsPot[‘ID’]; ?>”>
<?php echo $row_rsPot[‘Plant_Name’]; ?>
</span></td>
<td class=”style9″><?php echo $row_rsPot[‘Pot_Size’]; ?></td>
<td>$
<input name=”txtPrice” type=”text” id=”txtPrice” value=”<?php echo $row_rsPot[‘Price’]; ?>” size=”6″> </td>
<td><p class=”style18″><label>
<span class=”style9″>
<input <?php if (!(strcmp($row_rsPot[‘InStock’],1))) {echo “checked”;} ?> name=”checkbox1″ type=”checkbox” id=”checkbox1″>
</span></label>
<span class=”style9″>In Stock
<input <?php if (!(strcmp($row_rsPot[‘InStock’],0))) {echo “checked”;} ?> name=”checkbox2″ type=”checkbox” id=”checkbox2″ value=”checkbox”>
Out of stock </span><label></label>
<span class=”style9″><label></label>
</span><br>
</p>
</td>
</tr>
<?php } while ($row_rsPot = mysql_fetch_assoc($rsPot)); ?>
<tr>
<td> </td>
<td> </td>
<td><input name=”Update” type=”submit” id=”Update” value=”Update”></td>
<td> </td>
</tr>
</table>
</form><?php
mysql_free_result($rsHours);
mysql_free_result($rsPot);
?>
[/code]