FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


What is useful way in this php+mysql problem?





shamil
I work with php+mysql. I have a table(1) with autoincrement field and it is linked to other table(2). I have to insert row to table(1). So when i insert row i have to know the incremented number to insert appropriate information to another table. What is best way to do that. Using minimum num of queries? Table is multiuser accessible.
mathiaus
Dont think I quite understand what your wanting but this should be helpful
http://www.phpfreaks.com/phpref/11.php
basiclly insert row into table 1
find the value
insert into table 2
shamil
mathiaus wrote:
Dont think I quite understand what your wanting but this should be helpful
http://www.phpfreaks.com/phpref/11.php
basiclly insert row into table 1
find the value
insert into table 2


If I do like you say and someone inserts new row before I find inserted value. Then it goes wrong. isin't it?
mathiaus
true but thats the simplest way. Rolling Eyes

You could use sessions on the page and inser the session id into table 1, queury table 1 for id where session id id that of the current page, use the found id to inser into table 2
kv
mysql_insert_id() will return you the last inserted auto increment value in the current session. This should solve your problem.
shamil
ok. i think the simplest way is to use mysql_insert_id(). thank you both.
Related topics
PHP, MySQL...
ASP +PHP+MySQL Tutorials
what is your php mysql apache installer package
Need some php/mysql dlls
The Basics (php, mysql etc)
PHP/Mysql - beginner!
A very good PHP MySQL Tutorial
Setup php,mysql and others...
php, mysql and iis5
 EASY 40 frih$ IF YOU KNOW PHP+MySQL 
Php Mysql security testing
Project to join - php,mysql??
Link PHP/Mysql with Outlook Express
Free PHP/MySQL login script
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.