Re: Inserting into multiple tables

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

 



On Sat, Apr 10, 2010 at 5:27 PM, Gary <gwpaul@xxxxxxx> wrote:

> I am experimenting with multiple tables, it is only a test that is my local
> machine only. This is the current code, which does not work , I have tried
> to concatonate the insert statements.  I have tried multiple $query
> variables, but it is just overwriting itself (only the last one gets
> inserted). I also tried writing the $query as an array, which got me an
> error message (saying it was expecting a string and I offered an array).
>
> Someone point me in the right direction?
>
>
I'm not aware of any multi-table insert syntax:
http://lists.mysql.com/mysql/171921

You'd have to perform 4 separate mysql_query() calls to accomplish what
you're looking for (one for each insert.)

That said, I'd recommend using a transaction so you make sure all of the
inserts succeed or fail together (it would cause issues down the road if one
table insert worked and another failed.)  Additionally, I'd recommend using
prepared statements to avoid SQL injection (I'd mention validation your POST
data, too ;)

See the tutorial below:
http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html

Adam

-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux