473,769 Members | 2,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

populating mysql using php

anfetienne
424 Contributor
hi this question is linked to this post ive made in the mysql section.

http://bytes.com/topic/mysql/answers...le#post3499253

simply i want to use a form to populate a table with the locations of images, thumbnails and their corresponding captions. i want to populate the table like this:

id image location thumbnail location caption

1 folder/image1.jpg folder/t/image1.jpg just a test
2 folder/image2.jpg folder/t/image2.jpg just the test
3 folder/image3.jpg folder/t/image3.jpg just to test

is it possible to loop php to insert data into more than one row in a mysql table like shown above?
Jul 14 '09
14 3767
dlite922
1,584 Recognized Expert Top Contributor
Dorm,

Don't worry, when i was learning PHP, if you had slapped me in the face then gave me the wrong answer, I'd still would have loved you for it :)

But that's just me, I love learning,



Dan
Jul 14 '09 #11
Dormilich
8,658 Recognized Expert Moderator Expert
yea, sometimes I wish I had a teacher for PHP… anyways, thanks Dan

Dorm the Worm *harhar*
Jul 14 '09 #12
anfetienne
424 Contributor
apology accepted....bei ng new to php doesn't exactly help me in any case.

thanks for the tip, ill give it a try as well
Jul 15 '09 #13
anfetienne
424 Contributor
ok ive done a test using prepared statements..... nice and fast but one problem....i dont know whether my loop is correct for this, it has worked when i done a multiple INSERT but only inserts 1 row with the prepared statements..

here is my code
Expand|Select|Wrap|Line Numbers
  1. <?php error_reporting(E_ALL);
  2.  
  3. $returnURL = $_POST['returnURL'];
  4.  
  5. if(isset($_POST['create_xml'])){
  6.  
  7. // configuration 
  8. $dbtype     = "sql"; 
  9. $dbhost     = "localhost"; 
  10. $dbname     = "theau10_resources"; 
  11. $dbuser     = "theau10_tawUser"; 
  12. $dbpass     = "auction10"; 
  13.  
  14. // database connection 
  15. $conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass); 
  16.  
  17. // query 
  18. $sql = "INSERT INTO flashGallery (id,imageLoc,thumbLoc,imageCap) VALUES (:id,:imageLoc,:thumbLoc,:imageCap)"; 
  19. $q = $conn->prepare($sql); 
  20.  
  21. foreach ($_POST['random_digit'] as $key => $random_digit)
  22. {
  23.   $q->execute(array(':id'=>$random_digit,
  24.                       ':imageLoc'=>$_POST['imageT'][$key],
  25.                     ':thumbLoc'=>$_POST['thumbnailT'][$key], 
  26.                     ':imageCap'=>$_POST['captionT'][$key])); 
  27.  
  28. }
  29.  
  30. }
  31. ?> 
  32.  
Jul 15 '09 #14
anfetienne
424 Contributor
problem solved....just had to change id to tempID for the project number and add a column id to auto increment

here is the final code

Expand|Select|Wrap|Line Numbers
  1. <?php error_reporting(E_ALL);
  2.  
  3. $returnURL = $_POST['returnURL'];
  4. $random_digit = $_POST['random_digit'];
  5.  
  6. // configuration 
  7. $dbtype     = "sql"; 
  8. $dbhost     = "localhost"; 
  9. $dbname     = "theau10_resources"; 
  10. $dbuser     = "theau10_tawUser"; 
  11. $dbpass     = "auction10"; 
  12.  
  13. // database connection 
  14. $conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass); 
  15.  
  16. // query 
  17. $sql = "INSERT flashGallery (imageNo,tempID,imageLoc,thumbLoc,imageCap) VALUES (:imageNo,:tempID,:imageLoc,:thumbLoc,:imageCap)"; 
  18. $q = $conn->prepare($sql); 
  19.  
  20. foreach ($_POST['picT'] as $key => $value)
  21. {
  22.   $q->execute(array(':tempID'=>$random_digit,
  23.                     ':imageNo'=>$value,
  24.                   ':imageLoc'=>$_POST['imageT'][$key],
  25.                 ':thumbLoc'=>$_POST['thumbnailT'][$key], 
  26.                                 ':imageCap'=>$_POST['captionT'][$key])); 
  27.  
  28. }
  29. ?> 
  30.  
Jul 15 '09 #15

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

Similar topics

2
3902
by: Jason | last post by:
I have a client that would like to have drop down menus added to a nav bar that is generated from MySQL. Is it possible to have a dynamically driven DHTML menu from MySQL? example link http://www.msnbc.msn.com/Default.aspx?p1=0
1
1997
by: Robert Kattke | last post by:
I'm designing a site for local music and entertertainment and have a few ?s that need to be cleared up. Currently, I'm working on the Club part and have a Contact Person form, and a Club form. For the Club form, I'd like to have up to 4 Contacts with various roles, {Booking, Manager, Owner, All}. Ideally, I'd like to have a frameset and have Contact form filled out 1st, allowing me to set a cookie that would populate the...
1
3121
by: Ward B | last post by:
Greetings. I'm somewhat new to this whole MySQL/PHP thing and need a little help. My web hosting service uses phpMyAdmin and at the bottom of the screen iis an area where I can upload a text file to populate a table. I have a table named groups with two fields: groups_id auto-increment primary groups_name
1
3213
by: kurty | last post by:
Hello all, I am currently working on a project (a web based database) which entails the use of HTML, PHP and MySQL. I am new to all of these languages and would like some assistance in solving the following problem that I have encountered: The project entails ADDing ,EDITing, DELETing records from a web based database. However the main objective of this project is to allow users to perform queries on the data in the database and then view the...
4
20114
by: prosad | last post by:
hello, Just solved a problem using Javascript onclick, can click on any cell in a dynamic table and it will pass the innerText object value to my form text field. parts of code given below: <script type="text/javascript"> function select_cell(obj) { document.getElementById('complaint').value = obj.innerText; document.getElementById('selected_form'); }
0
1078
by: xhermit | last post by:
I'm creating a wiki-style website with a mysql database. I'm not to this point yet, but I'm thinking ahead of when I'll need to start populating the database. Obviously the point is for users to populate it themselves, but I've been to several travel wiki websites and it seems like they almost share identical information. Is there some sort of central data I could tap into? Or just wishful thinking? For instance, lets say I wanted...
2
9048
by: eihabisaac | last post by:
Hi everyone I'm using VS2005 C# with MySQL to do a windows application i'm also using Devart for MySQL i was able to populate a combobox from the database but i really want to populate the other combobox based on the first combo value
2
4555
by: eihabisaac | last post by:
hi all im using C# with mysql i want to populate the menustrip items based on the select statement bellow i can select the items from the table and show them but how to popule the MenuStrip private void Form2_Load(object sender, EventArgs e) { textBox1.Text = general.profile.getX().ToString();
14
4339
by: Philth | last post by:
Hi there, I've essentially got a form with several drop down, each populated by columns in various tables. The populating bit works fine - the column rows appear as they should in the menu. Ideally the user needs to make their selections, and enter the form into a new database table. The problem is, when the selection is entered into the new table, only the first word of the string is entered. For example, the drop down may have...
0
9586
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10043
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9861
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7406
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3956
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
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.