Web Analytics Made Easy -
StatCounter Trouble with Insert last ID - CodingForum


No announcement yet.

Trouble with Insert last ID

  • Filter
  • Time
  • Show
Clear All
new posts

  • Trouble with Insert last ID

    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.

    PHP Code:
    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()); 
    PHP Code:
        mysql_query("INSERT INTO `image` (Upload) VALUES ('$file_name')")or die(mysql_error()); 
    PHP Code:
    $query "INSERT IGNORE INTO parts (description,number) VALUES ('" $description[$key] . "', '" $val "')";
    mysql_query($query) or die(mysql_error().$query); 

  • #2
    try mysql_insert_id()
    Mortgage Calculator | Debt Free


    • #3
      you can use last_insert_id in your mysql code, mysql_insert_id within your php code. you can't use either when you are not using an auto incremented column.