/    Sign up×
Community /Pin to ProfileBookmark

Multiple descriptions

I have a form that uploads multiple images and that works just as I need it to. But I cant seem to get the description to add to the database. I just get [0] [1] and so on.

Here is my form.

echo “<form method=”post” enctype=”multipart/form-data” action=”manageimage.php?view=addpictures&userId=$userId&upload=files”>”;

$i=0;
while ($i < $_REQUEST[howmany] && $i < 5) {

echo “<input type=”hidden” name=”MAX_FILE_SIZE” value=”4194304″>
Image: <input type=”file” name=”userimage[]”><br>
<input type=”hidden” name=”imagemax” size=”4″ value=”168″>
Description: <input type=”text” name=”description$i” size=”24″><br><br>”;

$i++;

}

echo “<input type=”hidden” value=”$i” name=”uploads”>”;
echo “<input type=”submit” value=”Upload Images”></form>”;

Here is my upload and database script:

$i=0;
while ($i < $_REQUEST[uploads]) {

/////////////CREATE A THUMBNAIL FOR VIEWING
if ($_FILES[‘userimage’][‘type’][$i]==”image/pjpeg”) {
$thesize = $_REQUEST[imagemax];
$newWidth = $thesize;
$newHeight = $thesize;
$srcImage = ImageCreateFromJPEG($_FILES[‘userimage’][‘tmp_name’][$i]);
$srcWidth = ImageSX($srcImage);
$srcHeight = ImageSY($srcImage);
if($srcWidth < $srcHeight)
{
$destWidth = $newWidth * $srcWidth/$srcHeight;
$destHeight = $newHeight;
}
else
{
$destWidth = $newWidth;
$destHeight = $newHeight * $srcHeight/$srcWidth;
}
$destImage = imagecreatetruecolor($destWidth, $destHeight);
ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
ImageJPEG($destImage, “/home/mattdudley/momadddidley.com/htdocs/BLOG/imageuploads/RESIZED”.basename($_FILES[‘userimage’][‘name’][$i]));
ImageDestroy($srcImage);
ImageDestroy($destImage);
} else { echo “There was an error while uploading your image!”;
include(‘footer.inc’);
exit;}

/////////IMAGE FILES AND TYPE
$thefile=$_FILES[‘userimage’][‘name’][$i];
$resized=”RESIZED$thefile”;
$type=”image”;

//////////DATE
$month = date(“F”);
$day = date(“d”);
$year = date(“Y”);

$thedate=”$month $day, $year”;

///////////TIME
$hour = date(“h”);
$min = date(“i”);
$apm = date(“a”);

$thetime=”$hour:$min $apm”;

///////////////////ADD IMAGES TO THE DATABASE
$addimages=”INSERT INTO imagesTable set
imageFile=’$thefile’,
resizedimageFile=’$resized’,
description=’$_REQUEST[description][$i]’,
uploaddate=’$thedate’,
uploadtime=’$thetime’,
userId=’$userId’,
imageType=’$type'”;
$adddoit=mysql_query($addimages);
echo mysql_error();

$i++;
}

I was thinking I should change the field name to description[] rather than description$i. But that just produced something else. I brain has been getting squeezed over this for a while. Any help or suggestions would be sweet. Thanks

[url]www.momadddidley.com[/url]

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceApr 11.2005 — If you keep [b]description$i[/b], then use this:

description=$_REQUEST['description'.$i]

If you change to [b]description[][/b], then use this:

description=$_REQUEST[description[$i]]

Though I'm still relatively new to PHP and am unsure of the last method. ?
Copy linkTweet thisAlerts:
@madddidleyauthorApr 11.2005 — I tried that and then tried to mix it up a little and kept on getting a parse error. Is there some way to specify the variable before the query? Thanks.
Copy linkTweet thisAlerts:
@phpnoviceApr 11.2005 — Is there some way to specify the variable before the query?[/quote]
$name = 'description'.$i;

$description = $_REQUEST[$name];
Copy linkTweet thisAlerts:
@madddidleyauthorApr 12.2005 — I can't seem to get past this. I tried it again and mixed it up again and all I still get is 0 1 2 or Array[0] and so on and so on.
Copy linkTweet thisAlerts:
@phpnoviceApr 12.2005 — #1 You need to look at the HTML that shows up in the browser and verify just as to what, exactly, are the field's names.

#2 Place PHP [b]echo[/b] statements throughout your code so that you can see both what execution path is being used and what is the value of certain strategic variables at each point during the execution. This is a tedious process, but you have to be exactly sure as to what your code is doing at every stage of the game.
Copy linkTweet thisAlerts:
@madddidleyauthorApr 12.2005 — I know the names of the fields go like description0, description1 and so on.


I know what needs to be done but I don't know how to do it. I keep on getting parse errors though. I need to increment this $dep= $_REQUEST[description];


I've tried:

$dep=$_REQUEST[description][$i]; (no parse errors, no results at all)

$dep=$_
REQUEST[description.$i];

$dep=$_REQUEST[description'.$i.'];

and anything else kind of like that. I am using the request because the global variables are turned off. Please someone help the squeeze of the brain.
Copy linkTweet thisAlerts:
@madddidleyauthorApr 12.2005 — Holy Crap! I got it. $dep=$_REQUEST[description][$i]; For some reason it decided to go.
Copy linkTweet thisAlerts:
@phpnoviceApr 12.2005 — I got it. $dep=$_REQUEST[description][$i]; For some reason it decided to go.[/QUOTE]
That should only work if your field names are: [b]name="description[]"[/b]

I posted incorrectly previously when I said that would be handled as this:

$_REQUEST[description[$i]];
×

Success!

Help @madddidley spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...