Re: Newbie - 2 tables one insert

From: Date: Wed, 24 Jan 2001 20:20:45 +0000
Subject: Re: Newbie - 2 tables one insert
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-6148@lists.php.net to get a copy of this message
Are you trying to get the auto_increment "id" used in the last Insert ? If so, try this function: // int mysql_insert_id(int [link_identifier] ); $last_id = mysql_insert_id($result); $sql2 = "INSERT INTO pages page_id values($last_id ); $result2 = mysql_query($sql2); HTH Jayme. http://www.conex.com.br/jjeffman -----Mensagem Original----- De: Rubanowicz, Lisa <lisa.rubanowicz@cnh.com> Para: Rubanowicz, Lisa <lisa.rubanowicz@cnh.com>; <php-db@lists.php.net> Enviada em: terça-feira, 23 de janeiro de 2001 11:54 Assunto: RE: [PHP-DB] Newbie - 2 tables one insert > I realised I just sent my password out needless to say I am just about to > change it. > All the Best > Lisa > > -----Original Message----- > From: Rubanowicz, Lisa [mailto:lisa.rubanowicz@cnh.com] > Sent: Tuesday, January 23, 2001 1:54 PM > To: php-db@lists.php.net > Subject: [PHP-DB] Newbie - 2 tables one insert > > > Hi all, > Could you please help me out on this one. > I want to create a web site using two tables. > 1. page_creation - Stores page_id and page_name to be shown on all > navigation bars. > 2. pages - Contains pg_id, page_id, etc etc. > I want to do an insert into page_creation to create a new page and then pass > the page_id to pages, so I know the info stored in "pages" relates to a > certain page (one to many relationship). In the code below I want this to > be an "Add a New web Page" where the user types in a Page Name shown in the > nav bar and it enters data as above. > I have been trying for three days now with different methods and it is > driving me mad. > Thank you in advance for your assistance > > > <? > if ($page_name) { > > $host="db9.pair.com"; > $user="c3po"; > $password="13Balreask"; > $dbasename="c3po_test"; > > mysql_pconnect("$host","$user","$password") > or die("Unable to connect to SQL server"); > mysql_select_db("$dbasename") or die("Unable to select database"); > > $sql1 = "INSERT INTO page_creation pagename"; > $sql1 = "values('$page_name')"; > $result = mysql_query($sql1); > $sql2 = "INSERT INTO pages page_id values('$result'); > $result2 = mysql_query($sql2); > } > else { > ?> > <HTML> > <HEAD> > </HEAD> > <BODY BGCOLOR="#FFFFFF"> > <FORM ACTION="test_2_tables.php" METHOD="POST"> > <INPUT TYPE=TEXT name="page_name" VALUE="<?echo $page_name ?>" > SIZE=20> > <INPUT TYPE=SUBMIT VALUE="Add a New Page"> > </FORM> > </BODY> > </HTML> > <? } > ?> > > > > > Lisa Rubanowicz > Case ITC, > Navan, Ireland > Tel: #353 (0)46 77663 > > lisa.rubanowicz@cnh.com <mailto:lisa.rubanowicz@cnh.com> > > >

« previous php.db (#6148) next »