Re: [PHP-DB] How to do an update with arithmetic from a user input
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 <[EMAIL PROTECTED]> Date: Thu, 12 Aug 2004 14:10:00 -0700 Subject: Re: [PHP-DB] How to do an update with arithmetic from a user input To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED], PHP DB <[EMAIL PROTECTED]> Justin Patrin <[EMAIL PROTECTED]> 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 - Part Number Description Quantity List Price Special Price Put on Hold %s\n\n", $row["part_number"]); printf("%s\n\n", $row["description"]); printf("%s\n\n", $row["qty"]); printf("%s\n\n", $row["list"]); printf("%s\n\n", $row["special"]); printf(" \n"); } ?> !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
Re: [PHP-DB] How to do an update with arithmetic from a user input
Justin Patrin <[EMAIL PROTECTED]> 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 - Part Number Description Quantity List Price Special Price Put on Hold %s\n\n", $row["part_number"]); printf("%s\n\n", $row["description"]); printf("%s\n\n", $row["qty"]); printf("%s\n\n", $row["list"]); printf("%s\n\n", $row["special"]); printf(" \n"); } ?>
Re: [PHP-DB] How to do an update with arithmetic from a user input
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 } - Original Message - From: Chip Wiegand <[EMAIL PROTECTED]> Date: Thu, 12 Aug 2004 13:24:05 -0700 Subject: Re: [PHP-DB] How to do an update with arithmetic from a user input To: [EMAIL PROTECTED] Cc: PHP DB <[EMAIL PROTECTED]> Justin Patrin <[EMAIL PROTECTED]> wrote on 08/12/2004 12:55:24 PM: > On Thu, 12 Aug 2004 12:46:19 -0700, Chip Wiegand > <[EMAIL PROTECTED]> 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 QuantityList 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 - === Part Number Description Quantity List Price Special Price Put on Hold %s\n\n", $row["part_number"]); printf("%s\n\n", $row["description"]); printf("%s\n\n", $row["qty"]); printf("%s\n\n", $row["list"]); printf("%s\n\n", $row["special"]); printf(" \n"); } ?> !DSPAM:411bcfbf286175080220868! -- 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
Re: [PHP-DB] How to do an update with arithmetic from a user input
Justin Patrin <[EMAIL PROTECTED]> wrote on 08/12/2004 12:55:24 PM: > On Thu, 12 Aug 2004 12:46:19 -0700, Chip Wiegand > <[EMAIL PROTECTED]> 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 QuantityList 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 - === Part Number Description Quantity List Price Special Price Put on Hold %s\n\n", $row["part_number"]); printf("%s\n\n", $row["description"]); printf("%s\n\n", $row["qty"]); printf("%s\n\n", $row["list"]); printf("%s\n\n", $row["special"]); printf(" \n"); } ?>
Re: [PHP-DB] How to do an update with arithmetic from a user input
On Thu, 12 Aug 2004 12:46:19 -0700, Chip Wiegand <[EMAIL PROTECTED]> 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 QuantityList 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?? > > but that doesn't work. I have pasted in the main part of the code below... > Thanks for any help you can provide, > > Chip Wiegand > Computer Services > Simrad, Inc > 425-778-8821 > 425-771-7211 (FAX) > > BTW, thanks for the replys to the first message, I was expecting the list > to be much more busy. > === > > > > width="90%" align="center"> > > Part Number > Description > Quantity > List Price > Special Price > Put on Hold > > > if (isset($submit)): > > $sql = "update refurbs set qty(qty - '$buy') order by 'description'"; > > $result = mysql_query($sql); > > $Colors = array('#ffcc99','#ffcc33'); > $I = 0; > > while ( $row = mysql_fetch_array($result)) > { > printf("%s\n\n", $row["part_number"]); > printf("%s\n\n", $row["description"]); > printf("%s\n\n", $row["qty"]); > printf("%s\n\n", $row["list"]); > printf("%s\n\n", $row["special"]); > printf(" > \n"); > } > ?> > > width="90%" align="center"> > > value="Submit" /> > > > > -- 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
[PHP-DB] How to do an update with arithmetic from a user input
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 QuantityList 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'"; but that doesn't work. I have pasted in the main part of the code below... Thanks for any help you can provide, Chip Wiegand Computer Services Simrad, Inc 425-778-8821 425-771-7211 (FAX) BTW, thanks for the replys to the first message, I was expecting the list to be much more busy. === Part Number Description Quantity List Price Special Price Put on Hold %s\n\n", $row["part_number"]); printf("%s\n\n", $row["description"]); printf("%s\n\n", $row["qty"]); printf("%s\n\n", $row["list"]); printf("%s\n\n", $row["special"]); printf(" \n"); } ?>