kenwvs
10-07-2006, 07:47 AM
I have a form that is completed and some data is put into a table called workorder, the images uploaded go into a table called images and the parts go in a table called parts.
I need to be able to retrieve these items so I have created tables that will tie the parts and images into the workorder table. (workorder_parts and workorder_images)
The problem is that when I try to get it to use the last_insert_id() it is only putting a 0 in the field. The other issue is that I am not sure how to tie in multiple rows from each workorder together. By this, I mean that their could be up to 4 images or 7 parts inserted into the table for each workorder.
This is how I have it setup right now, but it isn't working. The initial data is going into the workorder, parts and images tables, but no data (only zeros) is going into the table that ties them together.
mysql_query("INSERT INTO workorder (work, name, sched, site, serial, hours, starts, issue, severity, resolution, assistance, safety) VALUES ('$work', '$name', '$sched', '$site', '$serial', '$hours', '$starts', '$issue', '$severity', '$resolution', '$assistance', '$safety')") or die(mysql_error());
//mysql_query("INSERT INTO workorder_parts (number, workorder_work_id) VALUES ('number[]', 'last_insert_id')")or die(mysql_error());
mysql_query("INSERT INTO workorder_image(image_image_id,workorder_work_id) VALUES ('$image_id', 'last_insert_id()')")or die(mysql_error());
mysql_query("INSERT INTO `image` (Upload) VALUES ('$file_name')")or die(mysql_error());
$query = "INSERT IGNORE INTO parts (description,number) VALUES ('" . $description[$key] . "', '" . $val . "')";
mysql_query($query) or die(mysql_error().$query);
I need to be able to retrieve these items so I have created tables that will tie the parts and images into the workorder table. (workorder_parts and workorder_images)
The problem is that when I try to get it to use the last_insert_id() it is only putting a 0 in the field. The other issue is that I am not sure how to tie in multiple rows from each workorder together. By this, I mean that their could be up to 4 images or 7 parts inserted into the table for each workorder.
This is how I have it setup right now, but it isn't working. The initial data is going into the workorder, parts and images tables, but no data (only zeros) is going into the table that ties them together.
mysql_query("INSERT INTO workorder (work, name, sched, site, serial, hours, starts, issue, severity, resolution, assistance, safety) VALUES ('$work', '$name', '$sched', '$site', '$serial', '$hours', '$starts', '$issue', '$severity', '$resolution', '$assistance', '$safety')") or die(mysql_error());
//mysql_query("INSERT INTO workorder_parts (number, workorder_work_id) VALUES ('number[]', 'last_insert_id')")or die(mysql_error());
mysql_query("INSERT INTO workorder_image(image_image_id,workorder_work_id) VALUES ('$image_id', 'last_insert_id()')")or die(mysql_error());
mysql_query("INSERT INTO `image` (Upload) VALUES ('$file_name')")or die(mysql_error());
$query = "INSERT IGNORE INTO parts (description,number) VALUES ('" . $description[$key] . "', '" . $val . "')";
mysql_query($query) or die(mysql_error().$query);