RE: [PHP] Update row problems
| From: | Steve Jackson | Date: | Mon, 27 Jan 2003 13:14:11 +0000 |
| Subject: | RE: [PHP] Update row problems | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-133235@lists.php.net to get a copy of this message | ||
I'm processing on a different page so what would I use instead of
$_POST?
print_r($_POST)
Didn't display anything or diagnose anything.
Steve Jackson
Web Developer
Viola Systems Ltd.
http://www.violasystems.com
stephen.jackson@violasystems.com
Mobile +358 50 343 5159
> -----Original Message-----
> From: Tim Ward [mailto:timward@chessish.com]
> Sent: 27. tammikuuta 2003 14:57
> To: Steve Jackson
> Subject: Re: [PHP] Update row problems
>
>
> sounds like $_POST[""catorder"] isn't an array - if
> you're posting to the same page you need to wrap
> the processing in something to test if the form has
> been posted (e.g. is_array($_POST[""catorder"])),
> or maybe you're using an older versionof PHP where
> $_POST isn't available -try using print_r($_POST)
> for diagnostics.
>
> Tim Ward
> http://www.chessish.com
> mailto:timward@chessish.com
> ----- Original Message -----
> From: Steve Jackson <stephen.jackson@violasystems.com>
> To: 'Tim Ward' <timward@chessish.com>
> Sent: Monday, January 27, 2003 12:52 PM
> Subject: RE: [PHP] Update row problems
>
>
> > Ok,
> >
> > I put the query in the loop and now I get this error?
> >
> > 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());
> > }
> >
> > Warning: Invalid argument supplied for foreach()
> > in
> /home/stephenj/public_html/viola/eadmin/eshop_processcatorder.php on
> > line 27
> >
> > Is it a $_POST problem? Using PHP 4.06
> >
> > Steve Jackson
> > Web Developer
> > Viola Systems Ltd.
> > http://www.violasystems.com
> > stephen.jackson@violasystems.com
> > Mobile +358 50 343 5159
> >
> >
> >
> >
> >
> > > -----Original Message-----
> > > From: Tim Ward [mailto:timward@chessish.com]
> > > Sent: 27. tammikuuta 2003 14:11
> > > To: PHP General; Steve Jackson
> > > Subject: Re: [PHP] Update row problems
> > >
> > >
> > > your query needs to be inside the foreach loop
> > > so that it runs for every item, at the moment it
> > > just runs after you've scanned through all the items
> > > so just does the last one.
> > >
> > > Tim Ward
> > > http://www.chessish.com
> > > mailto:timward@chessish.com
> > > ----- Original Message -----
> > > From: Steve Jackson <stephen.jackson@violasystems.com>
> > > To: PHP General <php-general@lists.php.net>
> > > Sent: Monday, January 27, 2003 11:46 AM
> > > Subject: [PHP] Update row problems
> > >
> > >
> > > > Hi all,
> > > >
> > > > I've been playing with this for a few hours now (over the
> > > course of a
> > > > couple of days) and it's getting frustrating!
> > > >
> > > > All I want to do is to be able to make one row in the
> > > database set the
> > > > order that my categories appear on my website. Now I can do
> > > this fine
> > > > simply by using ORDER_BY but I want to have my users be
> > > able to update
> > > > the order through an admin page like so:
> > > >
> > > > -------------------------------------
> > > > Catid | catname | catdesc | catorder |
> > > > 1 name desc 1
> > > > 2 name desc 2
> > > > 3 name desc 3
> > > > 4 name desc 4
> > > > ______________________________________
> > > >
> > > > Basically I have a form which takes data from the table
> above and
> > > > displays catname (just echoed) and catorder in a text form
> > > field. When
> > > > I submit the form I want to update catorder with whatever
> > > number the
> > > > user puts in the field.
> > > >
> > > > Currently my code updates only one of the category order
> > > numbers. So
> > > > my form code:
> > > >
> > > > <form action="eshop_processcatorder.php"
> > > > method="post">
> </td></tr>
> > > > <? while ($array = mysql_fetch_array($mysql))
> > > > {
> > > > echo "<tr><td width='150'><span
> > > > class='adminisoleipa'>";
> > > > echo "{$array["catname"]}";
> > > > echo "</td><td><input type='text'
> > > > size='2'
> > > > name='catorder[{$array["catid"]}]'
> value='{$array["catorder"]}'>";
> > > > echo "</span></td></tr>";
> > > > }
> > > > ?>
> > > > <tr><td><br>
> > > > <input type="submit" name="Submit"
> > > > value="Submit" class="nappi">
> > > > </form>
> > > >
> > > > That does everything I need it to do.
> > > >
> > > > However what am I doing wrong when I try to process it
> using this
> > > > code?
> > > >
> > > > 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());
> > > > if (!$result)
> > > > {
> > > > echo "<table width='100%' border='0'
> > > > cellspacing='0'
> > > > cellpadding='0' align='center'
> > > > bgcolor='#629D39'>";
> > > > echo "<tr><td><img
> > > >
> > > > src='images/admin_orders_administrate.gif'></td></tr>";
> > > > echo "<tr><td> </td></tr>";
> > > > echo "<tr><td><span class='adminisoleipa'>Could
> > > > not change
> > > > details: please <a
> > >
> > > href='mailto:stephen.jackson@violasystems.com'>click
> > > > here</a> to email the
> > > > administrator<br><br></span>";
> > > > echo "</td>";
> > > > echo "</tr>";
> > > > echo "</table>";
> > > > }
> > > > else
> > > > {
> > > > echo "<table width='100%' border='0'
> > > > cellspacing='0'
> > > > cellpadding='0' align='center'
> > > > bgcolor='#629D39'>"; echo
> > > > "<tr><td><img
> > > >
> > > > src='images/admin_orders_administrate.gif'></td></tr>";
> > > > echo "<tr><td> </td></tr>";
> > > > echo "<tr><td><span class='adminisoleipa'>The
> > > > category page has
> > > > had the order in which categories appear
> changed.<br><br></span>";
> > > > echo "</td>"; echo "</tr>";
> > > > echo "</table>";
> > > > }
> > > >
> > > > Any help appraciated.
> > > > Kind regards,
> > > >
> > > > Steve Jackson
> > > > Web Developer
> > > > Viola Systems Ltd.
> > > > http://www.violasystems.com
> > > > stephen.jackson@violasystems.com
> > > > Mobile +358 50 343 5159
> > > >
> > > >
> > > > --
> > > > PHP General Mailing List (http://www.php.net/)
> > > > To unsubscribe, visit:
> > > > http://www.php.net/unsub.php
> > > >
> > > >
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> >
> >
>