inset data to multiple tables

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

 



I am trying to find a solution to enter data from a web page to several
tables in the same database; actually,  I have 9 tables bus several are
basically id fields for foreign keys.
So far, I have found:
"use mysql_insert_id()" - the examples and directions are
incomprehensible (to me, anyway)
"use several insert statements" - what do you mean by that?

The following is what I am trying to use - the first INSERT INTO books
works fine.  The rest, no.
The string $some_fieldIN are values from input statements.

$sql1 = "INSERT INTO books ( title, sub_title, descr, comment, bk_cover, publish_date, ISBN, language ) VALUES ('$titleIN', '$sub_titleIN', '$descrIN','$commentIN', '$bk_coverIN', '$publish_dateIN', '$ISBNIN', '$languageIN')";

$result1 = mysql_query($sql1, $db);
		
$sql1 = "INSERT INTO authors (first_name, last_name) VALUES ('$first_nameIN', '$last_nameIN')";
		
$result = mysql_query($sql1, $db);
		
$sql1 =	"INSERT INTO publishers	(publisher) VALUES ('$publisherIN')";	

$result = mysql_query($sql1, $db);

Obviously, I don't understand anything here.
Questions:
1.  Do we really need the statements - $result1 = mysql_query($sql1,
$db); ? Why? What purpose do they serve?

2. How can one use "mysql_insert_id()" to insert data into multiple
tables? Why would you need to insert an id - especially since there are
only 2 fields in the pulblishers table (above) - id (auto-increment) and
publishers? As I ;understand it, when the id field is auto-increment, a
simple

INSERT INTO publishers	(publisher) VALUES ('$publisherIN') works fine (but not above)

Can somebody suggest anything? TIA


-- 

Phil Jourdan --- pj@xxxxxxxxxxxxx
   http://www.ptahhotep.com
   http://www.chiccantine.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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