/    Sign up×
Community /Pin to ProfileBookmark

insert into two or more tables

Can i insert into more than one table within one insert query using PHP and mySQL??

example:

[code=php]mysql_query(“INSERT INTO $db_table ( `event_id` , `event_day` , `event_month` , `event_year` , `event_time` , `title` , `description` , `type_event` ) VALUES (”, ‘$_POST[day]’, ‘$_POST[month]’, ‘$_POST[year]’, ‘$_POST[hour]:$_POST[minute]’, ‘$_POST[title]’, ‘$_POST[description]’ , ‘$_POST[type_event]’)”);[/code]

of course:

[code=php]$db_table = $TBL_PR = “events”;
and $TBL_PR = “events”;[/code]

but if i change

[code=php]$TBL_PR = “events”;[/code]

to

[code=php]$TBL_PR = “events, second_table, third_table, forth_table”;[/code]

Can this work, or would i have to make seperate Insert into query’s for every other table i want to insert data into and retrive from???

thanks ?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@_TeKKeD_authorMar 30.2005 — anyone ????

I need to be able to insert more fields into a database and have it display all the correct fields. I'm using this calendar script: http://www.scoznet.com/hyabusa/

Can anyone help me out!!!
Copy linkTweet thisAlerts:
@ShrineDesignsMar 30.2005 — they have to be done as seperate queries
Copy linkTweet thisAlerts:
@Stephen_PhilbinMar 30.2005 — You can perform all the seperate queries as one atomic transaction if it is necessary for all the queries to be executed simultaneously and that they must all be sucessful or all fail (as opposed to having some work and some fail which could cause havok in most systems).

To use transactions though, your database tables must use the InnoDB engine. They will not work with the MyISAM (or ISAM) engine tables;
Copy linkTweet thisAlerts:
@_TeKKeD_authorMar 31.2005 — I'm really stuck can someone atleast give me an example on how to do this with the app in the download link?
×

Success!

Help @_TeKKeD_ spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...