How to insert data into existing row

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
infomamun
Forum Contributor
Posts: 102
Joined: Mon Dec 28, 2009 7:48 pm

How to insert data into existing row

Post by infomamun »

Hi there,
Suppose I have a mysql table like this

Table:multiple
================================
id | date | colA | colB | colC | colD |
================================

Now, I have two cron job setted. cronA.php will have to insert data like this way:
INSERT into MULTIPLE (date, colA, colB) Values(23-09-10,2305,2306)

while a second cron job will execute the cronB.php at later, I want to add data somethin like this:
INSERT into MULTIPLE(colC,colD)Values(2407,208) WHERE date="23-09-10"

i.e I want to add values for colA & ColB at one time and values for colC and colD at later time for the same row (suppose, row id is 10 in both cases)

is it possible? If yes,then please mention the php syntax for this type of job.

Regards.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: How to insert data into existing row

Post by s.dot »

You will want to use an UPDATE query
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
suleman
Forum Newbie
Posts: 3
Joined: Sat Oct 30, 2010 3:07 am

Re: How to insert data into existing row

Post by suleman »

you need update query instead of insert query
infomamun
Forum Contributor
Posts: 102
Joined: Mon Dec 28, 2009 7:48 pm

Re: How to insert data into existing row

Post by infomamun »

I have a confusion. I think I have to insert at first then the update by second cron job. Because without insert how id will be autoincremented? And if id will not be incremented then how can I update fields, because I have to run query like this:

update colB where id=3 , is not it?


so I have to insert at first like this:
insert date value 1-11-2010
then
update colB where id=2/3 or whatever?

Any alternative way?
Post Reply