Re: How to do an update with arithmetic from a user input

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Justin Patrin <papercrane@xxxxxxxxx> wrote on 08/12/2004 12:55:24 PM:

> On Thu, 12 Aug 2004 12:46:19 -0700, Chip Wiegand
> <chip.wiegand@xxxxxxxxxx> wrote:
> > I have an existing database and web page showing the query results. I 
have
> > added another field to allow a user to input a two digit number. I 
want
> > that number to change the number in one of the existing columns for 
the
> > item it was input next to.
> > I have these columns -
> > 
> > Part Number     Description     Quantity        List Price      Put on
> > hold
> > 
> > I want the Quantity column changed according to the number the user 
input
> > in the Put on hold column.
> > I'm stuck in the query to write, trying to do
> > 
> > $sql1 = "update refurbs set qty(qty - $qty) order by 'description'";
> 
> Perhaps:
> $sql1 = "update refurbs set qty = qty - $qty";
> 
> Also,
> 1) you have no WHERE there, so this will update *all* records.
> 2) why are you trying to order an update??

Thanks for the quick reply. The order by stuff is gone now, it was an 
'artifact'. hehe. Anyway, I added the where clause so my query looks like 
this:

$sql = "update refurbs set qty = qty - $buy where part_number = 
$part_number"; 

But when I try to run this I get an error -

Parse error: parse error, unexpected $ in 
/usr/local/www/data-dist/auth_dealers/refurbs-test.php on line 102 

I don't see an rogue $'s in the code.
(Eventually the form will submit to another page which will email the info 
to a person here in our office).
--
Chip
Now the code looks like this -
===============================================================
<form action="<? PHP_SELF ?>" method="post" name="refurbs">

<table summary="" border="1" cellpadding="5" cellspacing="0"
width="90%" align="center">
<tr>
<td class="small" bgcolor="#ffffff">Part Number</td>
<td class="small" bgcolor="#ffffff">Description</td>
<td class="small" bgcolor="#ffffff">Quantity</td>
<td class="small" bgcolor="#ffffff">List Price</td>
<td class="small" bgcolor="#ffffff">Special Price</td>
<td class="small" bgcolor="#ffffff">Put on Hold
</td>
</tr>
<? 
if (isset($submit)):

$sql = "update refurbs set qty = qty - $buy where part_number = 
$part_number"; 
 
$result = mysql_query($sql); 

$Colors = array('#ffcc99','#ffcc33');
$I = 0; 

while ( $row = mysql_fetch_array($result)) 
{
printf("<tr bgcolor=" . $Colors[ $I ++ % count( $Colors ) ] . 
"><td>%s\n</td>\n", $row["part_number"]); 
printf("<td>%s\n</td>\n", $row["description"]);
printf("<td>%s\n</td>\n", $row["qty"]);
printf("<td>%s\n</td>\n", $row["list"]);
printf("<td>%s\n</td>\n", $row["special"]);
printf("<td><input type=\"text\" name=\"buy\" size=\"2\" maxlength=\"2\"> 
</td></tr>\n");
} 
?>
</table>
<table summary="" border="0" cellpadding="5" cellspacing="0"
width="90%" align="center">
<tr>
<td><br /><div align="center"><input type="submit" name="submit" 
value="Submit" /></div></td>
</tr>
</table>
</form>

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux