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

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

 



You don't need the colon as well as the curly brace on your if. Again:

if (isset($submit))
{ 
  //do stuff
}

Your update query doesn't say anything about the description, I don't
see how it could eb affected.

Also, looks like you're using register_globals. Check out this page
and the links for more info on why this is bad:
https://www.reversefold.com/tikiwiki/tiki-index.php?page=PHPFAQs

----- Original Message -----
From: Chip Wiegand <chip.wiegand@xxxxxxxxxx>
Date: Thu, 12 Aug 2004 14:10:00 -0700
Subject: Re:  How to do an update with arithmetic from a user input
To: papercrane@xxxxxxxxxxxxxxx
Cc: papercrane@xxxxxxxxxxxxxxx, PHP DB <php-db@xxxxxxxxxxxxx>

 
Justin Patrin <papercrane@xxxxxxxxx> wrote on 08/12/2004 01:37:35 PM:
 
 > Unless $part_number is a number, you're going to want to put quotes
 > around it. Well, actually, you want to run mysql_real_escape_string()
 > on it.
 > 
 > You also don't seem to have an end to that if statement. Usually,
 > people use curly braces around those:
 > 
 > if(true) {
 >   //do something
 > }
 
Thanks, I'm making headway. This time when I entered a value and
submitted, the database value for the qty field was not changed, but
instead the description field was cleared. The database table has
columns titled qty as well as description and others.
 
Regards, 
Chip 
 
The newest version of the code is this - 

 <form action="refurbs-send.php" 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); 
} 
else: 
$sql = "select * from refurbs order by description"; 
$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> !DSPAM:411bda82311752080024828! 



-- 
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder

paperCrane --Justin Patrin--

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


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

  Powered by Linux