473,543 Members | 2,917 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to insert multiple images path to database

250 Contributor
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 10665
johny10151981
1,059 Top Contributor
HOw about this structture?
AutoId-----UserId-----UserPicture
1-----User1-----UserPicture1
2-----User2-----UserPicture2
3-----User3-----UserPicture3
Aug 26 '11 #2
ghjk
250 Contributor
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 Contributor
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
33287
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', '$e')"; I want to insert 5 rows at a time in the database, but it only inserts every 5th record. For example: 1. AA
8
5505
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, UPDATE, DELETE) which are controlled by a web frontend and the table records are manipulated to control the permissions. Example: The Press...
5
7018
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
4318
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 b 1 4 c 1 5 d
3
8231
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
1587
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 textboxes and rows in an html table, I decided to do so in a gridview; however, I'm not sure if this is even possible. What I wish to do is: 1)...
0
1282
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 from the url string Imagename = DropDownList1.SelectedItem .Text ; //string Imagename = Request.QueryString; //build our query...
11
4144
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 user's related images like below: Id First Name Last Name Title Image1 Image2 Image3
0
3242
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. <%@ page import ="java.sql.*,java.util.*,java.awt.*,java.io.*" %> <%
3
1693
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());
0
7401
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7344
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7589
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7681
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5881
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4886
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1810
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.