473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Updating multiple records

Hi,

I have a MySQL database where I want to updated multiple records. The
table has two columns:
product_number
product_price

I have a list with first entry product_price, second entry
product_number

@products_param = (

['11.90', '1034K'],
['22.90', '1034R'],
['43.90', '1034U']

); # no comma after last entry

I run the following from a file on the server:

$dbh = DBI->connect($dsn, $login_name, $password)
or die "(Can't connect to MySQL database: $DBI::errstr\n";

####### Start products_param FOR loop

$dbh = DBI->connect($dsn, $login_name, $password)
or die "(Can't connect to MySQL database: $DBI::errstr\n";

###### Start products_param FOR loop ######

$compiled = $dbh->prepare("

UPDATE products
SET products_price = ?
WHERE products_model = ?
VALUES (?,?)

");

foreach ($products_param as $products) {

$dbh->execute($compiled, $products);

};

This gives me an "Internal Server" error. I have several PHP and MySQL
books but cannot find the correct syntax.

Any help appreciated.

Al Moodie.
Sep 2 '08 #1
6 1788
On Sep 2, 11:37*am, Al Moodie <nos...@nospam.comwrote:
Hi,

I have a MySQL database where I want to updated multiple records. The
table has two columns:
product_number
product_price

I have a list with first entry product_price, second entry
product_number

@products_param = (

* * * * * * * * ['11.90', '1034K'],
* * * * * * * * ['22.90', '1034R'],
* * * * * * * * ['43.90', '1034U']

* * * * * * * * ); # no comma after last entry

I run the following from a file on the server: * * * * *

$dbh = DBI->connect($dsn, $login_name, $password)
or die "(Can't connect to MySQL database: $DBI::errstr\n";

####### Start products_param FOR loop

$dbh = DBI->connect($dsn, $login_name, $password)
or die "(Can't connect to MySQL database: $DBI::errstr\n";

###### Start products_param FOR loop ######

$compiled = $dbh->prepare("

* * * * UPDATE products
* * * * SET products_price = ?
* * * * WHERE products_model = ?
* * * * VALUES (?,?)

* * * * ");

foreach ($products_param as $products) {

$dbh->execute($compiled, $products);

};

This gives me an "Internal Server" error. I have several PHP and MySQL
books but cannot find the correct syntax.

Any help appreciated.

Al Moodie.
seems to be error in this
where have you declared this?

@products_param = (

['11.90', '1034K'],
['22.90', '1034R'],
['43.90', '1034U']

);

---------------------
http://www.webxan.com
---------------------
Sep 2 '08 #2
On 2 Sep, 16:37, Al Moodie <nos...@nospam.comwrote:
Hi,

I have a MySQL database where I want to updated multiple records. The
table has two columns:
product_number
product_price

I have a list with first entry product_price, second entry
product_number

@products_param = (

* * * * * * * * ['11.90', '1034K'],
* * * * * * * * ['22.90', '1034R'],
* * * * * * * * ['43.90', '1034U']

* * * * * * * * ); # no comma after last entry

I run the following from a file on the server: * * * * *

$dbh = DBI->connect($dsn, $login_name, $password)
or die "(Can't connect to MySQL database: $DBI::errstr\n";

####### Start products_param FOR loop

$dbh = DBI->connect($dsn, $login_name, $password)
or die "(Can't connect to MySQL database: $DBI::errstr\n";

###### Start products_param FOR loop ######

$compiled = $dbh->prepare("

* * * * UPDATE products
* * * * SET products_price = ?
* * * * WHERE products_model = ?
* * * * VALUES (?,?)

* * * * ");

foreach ($products_param as $products) {

$dbh->execute($compiled, $products);

};

This gives me an "Internal Server" error. I have several PHP and MySQL
books but cannot find the correct syntax.

Any help appreciated.

Al Moodie.
I have never seen that syntax for the execute method. Where are you
getting it from?
Sep 2 '08 #3
On Tue, 2 Sep 2008 09:00:05 -0700 (PDT), Captain Paralytic
<pa**********@yahoo.comwrote:
>
I have never seen that syntax for the execute method. Where are you
getting it from?
I "adapted" it from an INSERT placeholder query in a PHP book. If you
know the correct sytax please let me know.

Al Moodie.
Sep 2 '08 #4
$compiled = $dbh->prepare("
>
UPDATE products
SET products_price = ?
WHERE products_model = ?
VALUES (?,?)

");
I think the VALUES line is a problem anyhow. It does not belong in an
UPDATE query.

If you want to know what happens, enable the querylog (in my.cnf). I
assume you are developing on your local database, where enabling the
querylog is not a space/performance issue.
To check the log "live" there are quite nice log viewers, like multitail
(linux) or BareTail (windows or wine). You can then see what is really
sent to the server.

Best regards,
--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
Sep 3 '08 #5
On Sep 2, 4:37 pm, Al Moodie <nos...@nospam.comwrote:
Hi,

I have a MySQL database where I want to updated multiple records. The
table has two columns:
product_number
product_price

I have a list with first entry product_price, second entry
product_number

@products_param = (

['11.90', '1034K'],
['22.90', '1034R'],
['43.90', '1034U']

); # no comma after last entry

I run the following from a file on the server:

$dbh = DBI->connect($dsn, $login_name, $password)
or die "(Can't connect to MySQL database: $DBI::errstr\n";

####### Start products_param FOR loop

$dbh = DBI->connect($dsn, $login_name, $password)
or die "(Can't connect to MySQL database: $DBI::errstr\n";

###### Start products_param FOR loop ######

$compiled = $dbh->prepare("

UPDATE products
SET products_price = ?
WHERE products_model = ?
VALUES (?,?)

");

foreach ($products_param as $products) {

$dbh->execute($compiled, $products);

};

This gives me an "Internal Server" error. I have several PHP and MySQL
books but cannot find the correct syntax.

Any help appreciated.

Al Moodie.
What's with the VALUES line? i've never seen that in a update
statement before.

If you want to update wveral rows at once so that a column holds the
same value you'd do UPDATE table SET column = ? WHERE key IN (?); KEY
would then take a list of keys seperated by commas. For example to
update rows with key values 3, 7 and 10 you'd pass 3,7,10 to the
prepared query.
Sep 3 '08 #6
On 2 Sep, 16:37, Al Moodie <nos...@nospam.comwrote:
Hi,

I have a MySQL database where I want to updated multiple records. The
table has two columns:
product_number
product_price

I have a list with first entry product_price, second entry
product_number
Hi Al,

I'd suggest re-writing your code in PHP and SQL - cos whatever you are
writing looks like neither:
@products_param = (

['11.90', '1034K'],
['22.90', '1034R'],
['43.90', '1034U']

); # no comma after last entry
I guess this is meant to be:

$products_param = array (
array ('11.90', '1034K'),
array ('22.90', '1034R'),
array ('43.90', '1034U')
); // no comma after last entry
(PHP will happily accomodate a trailing , in the array params - some
codingstandards even require it).

UPDATE products
SET products_price = ?
WHERE products_model = ?
VALUES (?,?)
WTF?

Do you mean
UPDATE products
SET products_price = ?
WHERE products_model = ?

C.
Sep 3 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: dukeofwhelmsley | last post by:
Hello, I have a database generated form that I would like users to be able to update by selecting a checkbox. Say the page displayed has six records on it and the user wants to delete one or more...
1
by: Roy Adams | last post by:
Hi everyone I'm trying to build a shopping cart app using a db the part I'm stuck on is the fact that, if someone adds a product that they have previously added to the cart. I've got it set up to...
6
by: Hennie de Nooijer | last post by:
Hi, Currently we're a building a metadatadriven datawarehouse in SQL Server 2000. We're investigating the possibility of the updating tables with enormeous number of updates and insert and the...
3
by: CSDunn | last post by:
Hello, I have an Access 2000 Project in which the data comes from a SQL Server 2000 database, and multiple users need to be able to see new records as each user adds records. The users also need...
3
by: Tc | last post by:
Hi, I was curious, I am thinking of writing an application that loads a dataset from a database that resides on a server. The question I have is this, if multiple copies of the app will be...
34
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have...
6
by: mike11d11 | last post by:
I'm trying to create an application that will have multiple users working off a table on a SQL server. Since multi users will be updating different records at any given moment, how can i get those...
10
by: chimambo | last post by:
Hi All, I have a little problem. I am retrieving records from a table and I want to update the records using checkboxes. I am able to display the database record quite alright and I have created...
0
by: jwbird | last post by:
I have a main form with multiple Subforms that are all displaying Datasheet information related to the Main form record. When I make changes/adds to the records(s) in the subform and tab to another...
5
by: Bill Schanks | last post by:
I have a winform app (VB 2005) that allows users to export data to excel, make updates to the excel file and import the data from that Excel file and update the database. My question is: Is it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.