Copy link to clipboard
Copied
I can upload a single image with a form to my MySql database with no problem. It sends the file name to the database then stores the image in an image file.
But now I want to upload multiple images in the same way from the same PHP page. Each multiple upload needs to be stored to a single record (designated user that's logged in). I have a field for each image in the database.
This may give you a better idea of what the database looks like:
| Username | ID | image1 | image2 | image3 |
|---|---|---|---|---|
| scmeeker | 5 | dotty.jpg | hello.jpg | kitty.jpg |
| jdmeeker | 7 |
So now I want to upload multiple images for each image field. When it works correctly, it should send the name of the image file to the proper field and then send the image to the image folder. I've tried it several ways with no luck at all.
Any one have any ideas???
Thanks!
I think you would be better off having two tables in you database. One would be a users table that has all of the user data including a user id (the primary key for this table and the foreign key for the other table). The second would be an images table. You would use the images table to upload infinite (well, as many as the db can handle) images. The trick, is that each record in the images table would have a foreign key, which would be the user id for the user that uploaded the image.
This way
...Copy link to clipboard
Copied
I think you would be better off having two tables in you database. One would be a users table that has all of the user data including a user id (the primary key for this table and the foreign key for the other table). The second would be an images table. You would use the images table to upload infinite (well, as many as the db can handle) images. The trick, is that each record in the images table would have a foreign key, which would be the user id for the user that uploaded the image.
This way your users wouldn't be limited to three images but could upload as many as you want to allow them to. The association of the user id, which has to be unique to each record in the users table (there cannot be duplicates, it should be your primary key on the users table), to the user id in any number of records in the images table is what will allow this to work.
EX:
The users table
| user_id | f_name | l_name | other_info | |
|---|---|---|---|---|
| 100001 | first | last | email@email.com | ... |
| 100002 | f_name | l_name | email@example.com | ... |
The images table
| image_id | src | user_id |
|---|---|---|
| 10000000001 | /db_imgs/img1.jpg | 100001 |
| 10000000002 | /db_imgs/img2.jpg | 100001 |
| 10000000003 | /db_imgs/img3.jpg | 100002 |
| 10000000004 | /db_imgs/img4.jpg | 100001 |
| 10000000005 | /db_imgs/img5.jpg | 100001 |
Copy link to clipboard
Copied
I am going to try this. Thank you for your reponse. ![]()
One question though. Since I can't have a primary key in each table, can the imageID that you created in the second table have auto numbering? It seems I couldn't apply that when I tried.
I'm fairly new to MySql, so I hope you can bear with me. Thank you. ![]()
Copy link to clipboard
Copied
scmeeker wrote:
I am going to try this. Thank you for your reponse.
One question though. Since I can't have a primary key in each table, can the imageID that you created in the second table have auto numbering? It seems I couldn't apply that when I tried.
Each table should have its own primary key field. In the users table you would want to call it user_id or something similar. In the images table you would have the image_id (or something named similar) be set up as the primary key for that table.
When I said you can't have duplicates I only meant that you can't have two instances of the user_id in the users table. For example, you could not have multiple records with their id as 100001. You can set MySQL to AUTO_INCREMENT a given field, such as a primary key.
However, you can have multiple instances of the user_id in the images table. That is called a foreign key. It is the primary key for a different table. It is a way to associate multiple sets of data (or images) to one record (user) in another table.
If you are using MySQL along with PHP you should look into using PHPMyAdmin. It provides a GUI for all of this that is easy to use and very reliable.
I'm fairly new to MySql, so I hope you can bear with me. Thank you.
No worries. I am new to plenty of things myself, like flash. I understand the feeling of not knowing how things work. ![]()
Copy link to clipboard
Copied
Thanks. ![]()
I do have PHPMyAdmin. But when I upload the two tables, it gives me an error when each table has one primary key in it. Then it will only allow one upload. But when I remove the primary key from the second table it lets me upload it. Does the foreign key have different code or code naming convention?
Thanks again for sharing, it is MUCH appreciated. ![]()
Copy link to clipboard
Copied
scmeeker wrote:
Thanks.
I do have PHPMyAdmin. But when I upload the two tables, it gives me an error when each table has one primary key in it. Then it will only allow one upload. But when I remove the primary key from the second table it lets me upload it. Does the foreign key have different code or code naming convention?
That is weird. Ok, well, you don't need to classify the image_id field as a primary key for this to work.
When you say that it only allows one upload, are you talking about importing the tables you created on your testing environment, to your hosting environment? Or what? When I use PHPMyAdmin I can simply choose a databse and then use the create new table section, then set up the table on the following page. I have never run into any problems creating multiple tables, or even having a primary key for each table.
Perhaps I am not understanding what exactly you are asking. What is the process you are going through?
Thanks again for sharing, it is MUCH appreciated.
You're welcome. Hopefully my answers will be helpful or even provide you with a correct solution.
Copy link to clipboard
Copied
When you say that it only allows one upload, are you talking about importing the tables you created on your testing environment, to your hosting environment?
Yes, I am importing my tables. Perhaps I should just create them in PHPmy Admin like you suggested. It seems that I would have more control over the outcome of the tables and can have multiple Primary Keys. Good idea. I'll have to brush up on that a bit...but it seems to be pretty straight forward. I've got my books. I checked in the PHPmyAdmin and saw what you were referring to. Thanks.
You're welcome. Hopefully my answers will be helpful or even provide you with a correct solution.
Your answers have been very helpful...thank you. I'll let you know how this goes. ![]()
Copy link to clipboard
Copied
scmeeker wrote:
When you say that it only allows one upload, are you talking about importing the tables you created on your testing environment, to your hosting environment?
Yes, I am importing my tables. Perhaps I should just create them in PHPmy Admin like you suggested. It seems that I would have more control over the outcome of the tables and can have multiple Primary Keys. Good idea. I'll have to brush up on that a bit...but it seems to be pretty straight forward. I've got my books. I checked in the PHPmyAdmin and saw what you were referring to. Thanks.
Yeah, if you have the ability to use PHPMyADMIN that is definitely the way to go. I just think it is sooooo much easier. Spend some time playing around with the features and GUI of PHPMyADMIN. That will help you. But again, it makes it a lot easier to be able to see all of your options.
You're welcome. Hopefully my answers will be helpful or even provide you with a correct solution.Your answers have been very helpful...thank you. I'll let you know how this goes.
Good to know.
Copy link to clipboard
Copied
This thread has been moved to the Dreamweaver Application Development forum, which deals with server-side issues.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more