/    Sign up×
Community /Pin to ProfileBookmark

Need Help updating Multiple records from one Form using PHP

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());
}
}
?>
[/code]


_____________________________________________________

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>&nbsp;</td>
<td>&nbsp;</td>
<td><input name=”Update” type=”submit” id=”Update” value=”Update”></td>
<td>&nbsp;</td>
</tr>
</table>
</form>

<?php
mysql_free_result($rsHours);
mysql_free_result($rsPot);

?>
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 27.2005 — Could you do us a favor and edit your message, and this time copy-and-paste your code in between [ php ] and [ /php ] tags (without the spaces I inserted in the tags here)? It should make it a lot easier to read your code.
Copy linkTweet thisAlerts:
@sgarrettauthorSep 27.2005 — I've edited the message down a bit - hope that is more readable

Thanks
×

Success!

Help @sgarrett spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...