Hi, I'm hoping someone can help me with this. I have just acquired a script that does uploads for images and I wanted to link the process my mysql records.

In my MySQL database, I have a primary key index which is an autonumber. what I want to do is this:
When I insert a record (which would include the image), I want the name of my uploaded image to be automatically changed to the autonumber of the record. I'm just not sure how to pull back that autonumber to be used with the image name.

Hope this makes sense. Thanks in advance!
Dealspecialist

    Hi,

    Short question: Do you know how to insert data into the database?

    Anyway..

    You would need something like:

    $query = "select * from TABLE where SOMECONDITION";
    
    $result = mysql_query($query) or die(mysql_error);
    
    while($row = mysql_fetch_array)
      {
       $myid = $row['YOURAUTONUMBERCOLUMNAME'];
      }
    
    echo "<img name=\"$myid.jpg\">";
    

      Originally posted by leatherback
      Short question: Do you know how to insert data into the database?

      Yes. That I know how to do that.

        Originally posted by leatherback
        Hi,

        Short question: Do you know how to insert data into the database?

        Anyway..

        You would need something like:

        $query = "select * from TABLE where SOMECONDITION";
        
        $result = mysql_query($query) or die(mysql_error);
        
        while($row = mysql_fetch_array)
          {
           $myid = $row['YOURAUTONUMBERCOLUMNAME'];
          }
        
        echo "<img name=\"$myid.jpg\">";
        

        [/B]

        So I have to do the insert first, as a separate step?
        What would be that SOMECONDITION? I think that is my missing component.

          Well,

          There is a whole range of steps.

          You upload the file.
          You get the information together you want to insert in the database
          You insert the information into the database
          You get the ID value for your image name
          You move the uploaded image to the new location/name

          After that you can retrieve it again in a -propably- seperate page. But you need to know which image you want to show. THat is where you need SOMECONDITIOn. This is something like 'where location=spain'. Or it could be 'where ID = $id' if you know which record you need.

          J.

            Thanks, I'll give that a try.

            I'll just need to search for some code to move the uploaded image to the new location/name; I wasn't aware that I could do that (unless you have something you would like to share with me)

            Nevermind just found it. Thanks again!!!
            http://fr2.php.net/manual/en/function.rename.php

              Hi,

              Well, with moving I mean.. The upload of a file by the file form thing only brings the file to the server, in a temp. folder. You should then move it to the location from which you want to use it in your website.

              Probably this is handled by your upload script. But.. I cannot look at it, nor do I have the mental capacity to visualize it without seeing it (jee, that's a buymmer, isn't it? WOuld be a nice skill to have!).

              If you are not sure, you could post the script and we can have a look at it. OR you can just give it a try, and get back to us if you get stuck.

              Remember: once it is working, it was well woirth the effort.!

              J.

                I think I can figure it out from here. Thanks again for your help!!!

                  Write a Reply...