473,414 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

How to insert multiple images path to database

250 100+
In my application I want to store vehicle details to mysql database. There is image field which is having more than 1 images.(select from the user) It may be 3 ,4 ,5 etc.image table has image id and image path field.When submit button click I want to add images to vehicle folder(this part working) and all images paths to the database. Really I'm wired now. I don't know how to add multiple images record to the database. Please help me. This is my existing code.

Expand|Select|Wrap|Line Numbers
  1. if (isset($_POST['Submit'])) {
  2.  
  3.     $vehicles_pk = mysql_insert_id(); // get last inserted vehicle id
  4.     $number_of_file_fields = 0;
  5.     $number_of_uploaded_files = 0;
  6.     $number_of_moved_files = 0;
  7.     $uploaded_files = array();
  8.     $upload_directory = dirname(__file__) . '/vehicles/'; //set upload directory
  9.  
  10.     // * we get a $_FILES['images'] array ,
  11.     // * we procee this array while iterating with simple for loop 
  12.     // * you can check this array by print_r($_FILES['images']); 
  13.  
  14.     for ($i = 0; $i < count($_FILES['images']['name']); $i++) {
  15.         $number_of_file_fields++;
  16.         if ($_FILES['images']['name'][$i] != '') { //check if file field empty or not
  17.             $number_of_uploaded_files++;
  18.             $uploaded_files[] = $_FILES['images']['name'][$i];
  19.             if (move_uploaded_file($_FILES['images']['tmp_name'][$i], $upload_directory . $_FILES['images']['name'][$i])) {
  20.                 $number_of_moved_files++;
  21.  
  22.             }
  23.  
  24.         }
  25.  
  26.     }
  27. $name= implode(',', $uploaded_files);
  28. echo $name; // this will print 1.jpg,2.jpg
  29.  
Aug 26 '11 #1
3 10653
johny10151981
1,059 1GB
HOw about this structture?
AutoId-----UserId-----UserPicture
1-----User1-----UserPicture1
2-----User2-----UserPicture2
3-----User3-----UserPicture3
Aug 26 '11 #2
ghjk
250 100+
Actually I want the help of insert query. I don't know how to do that for multiple values.(one field has multiple values)
Aug 26 '11 #3
ghjk
250 100+
I have done it. This is the code..
Expand|Select|Wrap|Line Numbers
  1. if (isset($_POST['Submit'])) {
  2.     echo $_SESSION['vehicles_pk'];
  3.     $number_of_file_fields = 0;
  4.     $number_of_uploaded_files = 0;
  5.     $number_of_moved_files = 0;
  6.     $uploaded_files = array();
  7.     $upload_directory = dirname(__file__) . '/vehicles/'; //set upload directory
  8.     // * we get a $_FILES['images'] array ,
  9.     // * we procee this array while iterating with simple for loop 
  10.     // * you can check this array by print_r($_FILES['images']); 
  11.  
  12.     for ($i = 0; $i < count($_FILES['images']['name']); $i++) {
  13.         //$number_of_file_fields++;
  14.         if ($_FILES['images']['name'][$i] != '') { //check if file field empty or not
  15.             $number_of_uploaded_files++;
  16.             $uploaded_files[] = $_FILES['images']['name'][$i];
  17.             if (move_uploaded_file($_FILES['images']['tmp_name'][$i], $upload_directory . $_FILES['images']['name'][$i])) {
  18.                $number_of_moved_files++;
  19.                 //echo $number_of_moved_files++;
  20.                 $sql ="INSERT INTO images  VALUES ('', '".$_SESSION['vehicles_pk']."','".$upload_directory . $_FILES['images']['name'][$i]."')";
  21.  
  22.                 $result = mysql_query($sql);
  23.  
  24.             }
  25.  
  26.         }
  27.         unset($_SESSION['vehicles_pk']);
  28.  
  29.     }
  30.  
  31. }
  32.  
  33.  
Aug 26 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: RotterdamStudents | last post by:
Hello there, i have a strange problem. I can't get php to insert multiple rows at once in a MySQL database. I use the $sql = "INSERT INTO database (a,b,c,d,e) VALUES ('$a', '$b' ,'$c', '$d',...
8
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE,...
5
by: SSP | last post by:
Dear ASP.NETers, How would I insert multiple rows of data from a web form? Are there any tute's and stuff around. Couldn't find any myself. Thanks in advance. SSP
3
by: Hai Nguyen | last post by:
Hi all I was attempting to insert multiple row by using a loop into a database.A table has 2 primary keys and one regular field (PR) (PR) ID Project Ans 1 2 a 1 ...
3
by: rajendrage | last post by:
I Want To Insert Multiple Records From Datagrid On One Click Of Save Button Insert All Values In Database
0
by: takallen | last post by:
Hello, I am designing a web page that is to be used as a data entry form. Each row contains 50 columns, and the web page will display about 25 rows. To save some time from creating so many ...
0
by: punitshrivastava | last post by:
Hi to All Senior's, I am working in Asp.net with C#. I am newbie in C#. So i want to fetch mutiple images from database .Database i am using is Sql Server. For this i code: //get the image id...
11
by: Jankie | last post by:
I need to dispaly a user's multiple images in one entry.Right now,say if a user uploads 3 images,three entries for the same id display to match 3 images. I only want 1 entry to display all of a...
0
selvasoft
by: selvasoft | last post by:
Hi Please help me any one. I want solution for display multiple images from oracle database.Using JSP. here is my code for display one image from database. Please Any one give me some ideas. ...
3
by: Hataf | last post by:
Hi! I am having a problem in displaying images from database. This the code gallery.php <?php session_start(); if(isset($_SESSION)){} //die('ERROR:'.mysql_error());
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.