Advanced Search

Results 1 to 5 of 5

Thread: Inserting records

  1. #1
    Join Date
    Sep 2008
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Inserting records

    I'll try to explain what i'm trying to achieve...

    I have 2 mysql tables one for items and another for images of the items.
    A form where the user will be adding/editing some items.

    Problem: When he goes to the form the record is not already created. The idea was to make an insert after. But the user can upload the images before saving the record or refreshing the page (uploading with iframe).
    How can i establish a relationship with the images uploaded and the current record?

    I thought maybe i could make an insert before go to the edit form, and then fetch the last record and do an update, but if another user is doing the same? maybe the record they fetch is the same, so i guess this is not a solution.

    Any ideas how to achieve this?

    Thanks
    Last edited by tuga; 11-20-2008 at 09:36 AM.

  2. #2
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    You could insert an ID number which is auto-incremental. that way it can't be assigned to more than one user.

  3. The Following User Says Thank You to jc_gmk For This Useful Post:

    tuga (11-20-2008)

  4. #3
    Join Date
    Sep 2008
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jc_gmk View Post
    You could insert an ID number which is auto-incremental. that way it can't be assigned to more than one user.
    Thanks but that was exactly what i'm doing.
    When he submits the form it is an incremental number as ID but the problem is that the user will be uploading images before he submits the form, that i have to associate with that ID, and i don't know which is before he submits the form.


    Thanks

  5. #4
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    Maybe you could create and insert the id before the form is even loaded?
    Then send that id to the form to be used for image insertion.

    you could make the code unique based on time.
    e.g.
    PHP Code:
    <?php
    $id 
    rand() . time();
    ?>

  6. The Following User Says Thank You to jc_gmk For This Useful Post:

    tuga (11-20-2008)

  7. #5
    Join Date
    Sep 2008
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I guess i found a solution
    Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.

    http://php.net/manual/en/function.mysql-insert-id.php

    I just make an insert and then use that value.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •