473,385 Members | 1,720 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,385 software developers and data experts.

populating mysql using php

anfetienne
424 256MB
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 #1
14 3710
anfetienne
424 256MB
ok i have solved how to insert multiple rows in sql but is it possible to loop this in php so it inserts the correct amount of rows for the amount of images?
Jul 14 '09 #2
Dormilich
8,658 Expert Mod 8TB
consider using a Prepared Statement (it's faster than multiple queries)
Jul 14 '09 #3
yes you can loop it exactly the no. of times the amount of images you have.
for that purpose u will have to set a variable to count the images. this variable will first check the no. of images and will restrict the loop to execute that many no. of times.
now how that can be done? u need to tell whr r the images stored & fetched from.
Jul 14 '09 #4
anfetienne
424 256MB
cant find anything on multiple insert with prepared statements
Jul 14 '09 #5
anfetienne
424 256MB
and pdkadam....i want to do this on upload not once its stored it will be alot easier that way because i can get this image and thumbnail locations once the code has been run in vars and then just add them into the sql (which is the last thing to run within the php script).

i think i will be using a foreach loop, i will set a array in the form called id[] but wont store this into the database as the project number will be stored as an id for later and easier retrieval. the images are already an array so therefore i have the captions to change to an array and then write my foreach loop....

i will be back with the results...thanks for the help guys
Jul 14 '09 #6
Dormilich
8,658 Expert Mod 8TB
@anfetienne
then you should read a bit more about prepared statements...

it basicly goes like this
Expand|Select|Wrap|Line Numbers
  1. // ...
  2. $ps->prepare($sql);
  3. foreach (...)
  4. {
  5.     // ...
  6.     $ps->execute($values);
  7. }
Jul 14 '09 #7
anfetienne
424 256MB
Dormilich i dont appreciate the manner or tone of your last message.....simple fact is the link you sent explained prepared statements i read the whole thing and nowhere on that page did it give an example or state anything about multiple inserts. moderator or not you just rude....your answer wasnt needed especially in that manner as i previously stated that i found my way that i will use and i will return the results later.

thanks but no thanks for the answer!
Jul 14 '09 #8
anfetienne
424 256MB
and i also searched it on google and for tutorials but it kept coming up with javascript!
Jul 14 '09 #9
Dormilich
8,658 Expert Mod 8TB
and i also searched it on google and for tutorials but it kept coming up with javascript!
I'd have thought you could have had a look at the PHP manual (eventually you need a PHP function to use Prepared Statements (just my train of thoughts)).

manual entry (further examples in the function discussions)

my google search

@anfetienne
1) I'm not modding PHP
2) I can't have a good day everytime. I'm a human after all and are bound to make mistakes
3) I'm sorry if I upset you

* – someone once told me that "reading the manual" is a rare skill nowadays…
Jul 14 '09 #10
dlite922
1,584 Expert 1GB
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 Expert Mod 8TB
yea, sometimes I wish I had a teacher for PHP… anyways, thanks Dan

Dorm the Worm *harhar*
Jul 14 '09 #12
anfetienne
424 256MB
apology accepted....being 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 256MB
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 256MB
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
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...
1
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. ...
1
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...
1
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...
4
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: ...
0
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...
2
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...
2
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 ...
14
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. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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...
0
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...

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.