Multiple images insert into database with one form

Title may be strange,

I was wondering if there is a way with PHP to make it so that multiple images links named test01.gif, test02.gif test03.gif etc, can be placed into the database without having to do them each seperately and without a loop.

why no loop?

where do the images come from?

how are they have to be named to make sure there are more?

how should the user insert them? multible fields? wildcards?

why no loop?
There is a difference between the amount of images added… sometimes it will be 10 and sometimes 20… (wasn’t sure if that made a difference in the code)

where do the images come from?
They are uploaded on the site and come from a certain folder

how are they have to be named to make sure there are more?
I can fill in the name at the form and I just need to add the 01.gif, 02.gif etc

how should the user insert them? multible fields? wildcards?
it’s the admin that inserts them with a field
It also inserts imagewidht, imageheight, how many images there are…

there is a secutety feature that wount alow a website to upload any files that the user hasn’t chosen.

this is a client problem, that can’t be solved with php, as long as php is just outputting html, cause html and javascript can’t do that.

if the users are trusting u, one possibility to get this done is to generate a .cmd or .sh file with php, that the user has to accept with the “open”-button of the download-dialog-box. and put code in there that is uploading the file via ftp.

an other way is to use a java-applet.

I don’t want to upload the images they are already uploaded.
I need an image link in the database to those images

[code]<?php if($_GET[‘do’] == add) {for($i=1;$i<=$totalcards;$i++) {$cardnum = sprintf("%02.0f", $i);
$deckname = addslashes($_POST[deckname]);
$descrip = addslashes($_POST[descrip]);
mysql_query(“INSERT INTO $tablename2 (id, deckname, deckfilename, cardnum, category, descrip, totalcards, cardwidth, cardheight, cardvalue, masterable) VALUES (’’,’$_POST[deckname]’,’$_POST[deckfilename]’,’$_POST[cardnum]’,’$_POST[category]’,’$_POST[descrip]’,’$_POST[totalcards]’,’$_POST[cardwidth]’,’$_POST[cardheight]’,’$_POST[cardvalue]’,’$_POST[masterable]’)”);
}
echo “

Success! The new deck has been added into the database.

”; }

else { ?>

Please fill out ALL of the information below to add a new card deck.

Deck Name:
Deck File Name:
Deck Description:
Category:
Total Cards:
Card Width:
Card Height:
Card Value:
Masterable: Yes No

[/code]

That is my current code, Now if I fill in the form it won’t work… if I however delete the sprintf line it will work, but it will only put one imagelink in the database not the 20 I want.

try [php]mysql_query("…") or die(mysql_error());[/php]

and [php]$cardnum = sprintf("%02d", $i); [/php]

and i don’t know whether that is missing, or not needed:[php]$totalcards=$_POST[‘totalcards’];[/php]

sorry now I just get a blank page.

Try putting error_reporting(E_ALL) at the top of your page. This should force the parser to show errors.

Even that gives me a blank page

I must be blonde

[quote=“Josien”]
not even “Success! The new deck has been added into the database.” ?

could u post the changed code again?

there should already be a notice about ($_GET[‘do’] == add) as it has to be ($_GET[‘do’] == “add”)

<?php error_reporting(E_ALL) session_start (); require('config.php'); if (! session_is_registered ( "$sessionreg" ) ) //if your variable isn't there, then the session must not be { session_unset (); //so lets destroy whatever session there was and bring them to login page session_destroy (); $url = "Location: index.php"; header ( $url ); } else //otherwise, they can see the page { ?>

that’s on top of the page now

[code]<?php if($_GET[‘do’] == add) {
$totalcards = $_GET[‘totalcards’]; for($i=1;$i<=$totalcards;$i++) $cardnum = sprintf("%02d", $i);
$deckname = addslashes($_POST[deckname]);
$descrip = addslashes($_POST[descrip]);
mysql_query(“INSERT INTO $tablename2 (id, deckname, deckfilename, cardnum, category, descrip, totalcards, cardwidth, cardheight, cardvalue, masterable) VALUES (’’,’$_POST[deckname]’,’$_POST[deckfilename]’,’$_POST[cardnum]’,’$_POST[category]’,’$_POST[descrip]’,’$_POST[totalcards]’,’$_POST[cardwidth]’,’$_POST[cardheight]’,’$_POST[cardvalue]’,’$_POST[masterable]’)”);
}
echo “

Success! The new deck has been added into the database.

”; }

else { ?>

Please fill out ALL of the information below to add a new card deck.

Deck Name:
Deck File Name:
Deck Description:
Category:
Total Cards:
Card Width:
Card Height:
Card Value:
Masterable: Yes No

[/code]

and the other php part! The rest is HTML

there is a semicolon missing after error_reporting(E_ALL).

and a ‘{’ behind for($i=1;$i<=$totalcards;$i++)

these are fatal errors, making ur script die before error_reporting(E_ALL) can be activated

do u have access to the php.ini ?

No I don’t,
my friends keep helping me and this is the only thing that still needs fixing…

The thing is if I remove the line with the sprintf it works, but that means I have to add the same thing 20 times with just changing the exit of the images…

I do get the line that it is submitted into the database but it’s not submitted

have u fixed the 2 syntax errors?

cause than there should be errors apearing that will help finding out where the problem with the loop is.

as u don’t have access to the php.ini, there is one more thing u can do to make errors showing up:

create a file called “.htaccess”

put the following code in there:

php_value error_reporting 6143 php_value display_errors 1

then upload/move the file in the same directory as ur script.

ooooh errors

Notice: Undefined index: do in /home/greylady.nl/www/tcgadmin/adddeck.php on line 27

Notice: Use of undefined constant add - assumed ‘add’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 28

Notice: Undefined index: totalcards in /home/greylady.nl/www/tcgadmin/adddeck.php on line 29

there are easy to fix:

[php]if($_GET[‘do’]==add)[/php] has to be

[php]if(isset($_GET[‘do’]) and $_GET[‘do’]==‘add’)[/php]

what happens after submitting the form?

Okay that was two errors less

This I get

Notice: Undefined index: totalcards in /home/greylady.nl/www/tcgadmin/adddeck.php on line 29

Success! The new deck has been added into the database.

has to be
$totalcards = $_POST[‘totalcards’];

what happens now?

Well a lot happens :o

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Notice: Use of undefined constant deckname - assumed ‘deckname’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 30

Notice: Use of undefined constant descrip - assumed ‘descrip’ in /home/greylady.nl/www/tcgadmin/adddeck.php on line 31

Notice: Undefined index: cardnum in /home/greylady.nl/www/tcgadmin/adddeck.php on line 32

Success! The new deck has been added into the database.

Sponsor our Newsletter | Privacy Policy | Terms of Service