Re: Problem with simple update
| From: | Marek Kilimajer | Date: | Fri, 24 Jan 2003 12:28:49 +0000 |
| Subject: | Re: Problem with simple update | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-132980@lists.php.net to get a copy of this message | ||
You must run
$result = mysql_query($query) or die("Query failure: " .mysql_error());
within the foreach loop, else $query will be only the last query assigned.
If you use get method in your form you need to use $_GET (or $_REQUEST) instead of $_POST
Steve Jackson wrote:
I can't get this to work. I am trying to update multiple rows at the same time? This is the code I have now adjusted to your specifications: <? while ($array = mysql_fetch_array($mysql)) { echo "<tr><td width='150'><span class='adminisoleipa'>"; //echo "<input type='hidden' name='categoryid{$array["catid"]}'>"; echo "{$array["catname"]}"; echo "</td><td><input type='text' size='2' name='catorder[{$array["catid"]}]' value='{$array["catorder"]}'> "; //echo "</td><td><input type='text' size='2' name='catorder' value='{$array["catorder"]}'>"; echo "</span></td></tr>"; } ?> And the action: foreach($_POST["catorder"] as $catid => $catorder) { $query = "update categories set catorder=$catorder where catid=$catid"; } $result = mysql_query($query) or die("Query failure: " .mysql_error()); The error: Warning: Invalid argument supplied for foreach() in eshop_processcatorder.php on line 27 Query failure: Query was empty Steve Jackson Web Developer Viola Systems Ltd. http://www.violasystems.com stephen.jackson@violasystems.com Mobile +358 50 343 5159-----Original Message----- From: Marek Kilimajer [mailto:kilimajer@webglobe.sk] Sent: 24. tammikuuta 2003 13:55 To: Steve Jackson Cc: PHP General Subject: Re: [PHP] Problem with simple update remove the hidden field and use <input type='text' size='2' name='catorder[{$array["catid"]}]' value='{$array["catorder"]}'> in action script you do foreach($_POST['catorder'] as $catid => $catorder) { update categories set catorder=$catorder where catid=$catid } Steve Jackson wrote:I am trying to set the order of a set of categories. Previously the catid field sorted the order of the categories. However Ichanged thisto Order By catorder and then set about writing a simpleupdate queryto allow people to set the order. I can't see anything wrong with this: Basically I pull the details from the categories DB into anarray andthen display in a table. This works fine <? while ($array = mysql_fetch_array($mysql)) { echo "<tr><td width='150'><span class='adminisoleipa'>"; echo "<input type='hidden' name='categoryid' value='{$array["catid"]}'>"; echo "{$array["catname"]}"; echo "</td><td><input type='text' size='2' name='catorder' value='{$array["catorder"]}'>"; echo "</span></td></tr>"; } ?> Then using this to update it seems to work till you checkthe update. Itsets the first two fields to one for some reason. $query = "update categoriesset catorder = '$catorder' where catid='$categoryid'";Any suggestions? Steve Jackson Web Developer Viola Systems Ltd. http://www.violasystems.com stephen.jackson@violasystems.com Mobile +358 50 343 5159