Question : How to get two new Primary keys, sent to two Foriegn keys

Hi,

I'm still pretty new to PHP, MySQL, and I'm using it in conjunction with Dreamweaver to create a classifieds section for a site.  I have a problem that is puzzling me.

I have created a form that creates new records in three tables in my WAMP database, the users table, classifieds table, and images table. I have figured out how to get the primary key from the users table (UserID), and place it into the foriegn key of the classifeds table (also UserID) using the INSERT_LAST_ID().  Now I need to insert the primary key from the classifieds table (ClassifiedsID) into the foriegn key of the images table (ClassifiedsID) so that I can associate the pictures with the images.  When I try to use the INSERT_LAST_ID(), it creates undesirable results.  Is there another method that I should be using in this case?

Below are the code snippets for the first INSERT_LAST_ID() (classifieds table) and the code I attempted for the second (images table).

Thanks,

Jerry
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
//first LAST_INSERT_ID()

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "for_salePostForm")) {
  $insertSQL = sprintf("INSERT INTO classifieds (CategoryID, TypeID, UserID, Title, `Description`, Location) VALUES (%s, %s, LAST_INSERT_ID(), %s, %s, %s)",
                       GetSQLValueString($_POST['CategoryID'], "int"),
                       GetSQLValueString($_GET['TypeID'], "int"),
                       GetSQLValueString($_POST['Title'], "text"),
                       GetSQLValueString($_POST['Description'], "text"),
                       GetSQLValueString($_POST['Location'], "text"));


//second LAST_INSERT_ID()

$insertSQL = sprintf("INSERT INTO images (ClassifiedsID, filename, mimetype, image, filesize) VALUES (LAST_INSERT_ID(), %s, %s, %s, %s)",
                       GetSQLValueString($_POST['filename'], "text"),
                       GetSQLValueString($_POST['mimetype'], "text"),
                       GetSQLValueString($_POST['image'], "text"),
                       GetSQLValueString($_POST['filesize'], "int"));

Answer : How to get two new Primary keys, sent to two Foriegn keys

The close request pending by optimus_nz states "optimus_nz has requested that this question be closed by accepting optimus_nz's comment #33092494  (0 points) as the solution for the following reason:
there is no RWW for plain server 2008."

This is what I said in comment 32967451 - "No, there is no Remote Web Workplace for standard server".  Why sis my comment not being accepted as an answer
Random Solutions  
 
programming4us programming4us