[PHP-DB] Arrays from forms....
I have a problem. I have done this before, but can't find the files. I am using the following function to upload files from a form. foreach ($_FILES[pictures][error] as $key = $error) { if ($error == UPLOAD_ERR_OK) { echo $error_codes[$error]; move_uploaded_file( $_FILES[pictures][tmp_name][$key], images/ .$_FILES[pictures][name][$key] ) or die(Problems with upload); } } I also need to insert the filenames of the uploaded files into a database. There are three fields in my db for these filenames, image1 image2 and image3. What would be the best way to get those filenames from the array into the vars $image1 $image2 and $image3? the first file in the array should be $image1 and so on. Thanks in advance. smime.p7s Description: S/MIME cryptographic signature
RE: [PHP-DB] Arrays from forms....
Sorry about that, not CC'ing the list... the values are not always empty, they should always have something in them... There should be 3 images uploading. But, I am sure just to make life interesting, there will be times when there could be as little as one uploaded. -Original Message- From: Chris [mailto:[EMAIL PROTECTED] Sent: Thursday, November 30, 2006 10:10 PM To: Gary E. Terry Cc: PHP DB Subject: Re: [PHP-DB] Arrays from forms Gary E. Terry wrote: I don't know if we are on the same page here... Maybe we are and I am just an idiot. The fields in my db are image1 image2 and image3. There are only three fields in the form that is being passed to the php script. But, on the form they are named pictures[]. Here is the full php I am using to process the form output: ?php include db.inc.back.php; foreach ($_FILES[pictures][error] as $key = $error) { if ($error == UPLOAD_ERR_OK) { echo $error_codes[$error]; move_uploaded_file( $_FILES[pictures][tmp_name][$key], bikeimages/ .$_FILES[pictures][name][$key] ) or die(Problems with upload); ${image.$key} = $_FILES['pictures']['name']; } } $make = $_POST['make']; $model = $_POST['model']; $year = $_POST['year']; $color = $_POST['color']; $description = $_POST['description']; $status = $_POST['status']; $query = INSERT INTO `inventory` (`make`, `model`, `year`, `color`, `description`, `image1`, `image2`, `image3`, `status`) VALUES ('$make', '$model', '$year', '$color', '$description', '$image1', '$image2', '$image3', '$status');; $result = mysql_db_query($db, $query) or displayErrorQuery ($query); echo meta http-equiv='refresh' content='0;URL=inventorylist.php'; ? $image1 $image2 and $image3 are not getting defined... Not real sure what's going on. Always cc the list so others can learn or suggest things. Are you uploading 3 images? Maybe define them first as well: foreach ($_FILES .. ) { ${image.$key} = ; if ($error == or do you mean the values are always empty? -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php smime.p7s Description: S/MIME cryptographic signature
RE: [PHP-DB] Arrays from forms....
If I print them, there's nothing. all three Here is the same file, in test mode... ?php include db.inc.back.php; foreach ($_FILES[pictures][error] as $key = $error) { if ($error == UPLOAD_ERR_OK) { echo $error_codes[$error]; move_uploaded_file( $_FILES[pictures][tmp_name][$key], bikeimages/ .$_FILES[pictures][name][$key] ) or die(Problems with upload); ${image.$key} = $_FILES['pictures']['name']; } } $make = $_POST['make']; $model = $_POST['model']; $year = $_POST['year']; $color = $_POST['color']; $description = $_POST['description']; //$image1 = $_POST['image1']; //$image2 = $_POST['image2']; //$image3 = $_POST['image3']; $status = $_POST['status']; echo $image1 -- $image2 -- $image3; /* $query = INSERT INTO `inventory` (`make`, `model`, `year`, `color`, `description`, `image1`, `image2`, `image3`, `status`) VALUES ('$make', '$model', '$year', '$color', '$description', '$image1', '$image2', '$image3', '$status');; $result = mysql_db_query($db, $query) or displayErrorQuery ($query); echo meta http-equiv='refresh' content='0;URL=inventorylist.php'; exit; */ ? I get -- -- outputted. -Original Message- From: Chris [mailto:[EMAIL PROTECTED] Sent: Thursday, November 30, 2006 10:39 PM To: Gary E. Terry Cc: php-db@lists.php.net Subject: Re: [PHP-DB] Arrays from forms Gary E. Terry wrote: Sorry about that, not CC'ing the list... the values are not always empty, they should always have something in them... There should be 3 images uploading. But, I am sure just to make life interesting, there will be times when there could be as little as one uploaded. If you print them out what's in them? echo $image1; echo $image2; I just realized that the $key probably starts at 0 instead of 1, so you might need to check that and then possibly: ${image.($key+1)} = $_FILES['pictures']['name']; -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php smime.p7s Description: S/MIME cryptographic signature
RE: [PHP-DB] Arrays from forms....
Nope... here is the output. -- -- Array ( [error] = ) -Original Message- From: Chris [mailto:[EMAIL PROTECTED] Sent: Thursday, November 30, 2006 10:56 PM To: Gary E. Terry Cc: php-db@lists.php.net Subject: Re: [PHP-DB] Arrays from forms Gary E. Terry wrote: If I print them, there's nothing. all three Here is the same file, in test mode... ?php include db.inc.back.php; foreach ($_FILES[pictures][error] as $key = $error) { if ($error == UPLOAD_ERR_OK) { echo $error_codes[$error]; move_uploaded_file( $_FILES[pictures][tmp_name][$key], bikeimages/ .$_FILES[pictures][name][$key] ) or die(Problems with upload); ${image.$key} = $_FILES['pictures']['name']; } } Hmm, looks ok. If you: print_r($_FILES[pictures]); and print_r($_FILES[pictures]['error']); do you get stuff there ? -- Postgresql php tutorials http://www.designmagick.com/ smime.p7s Description: S/MIME cryptographic signature
RE: [PHP-DB] Arrays from forms....
OK.. I am a moron.. Forgot that I had changed the name of the field in the form, and got sidetracked and didn't change it in the php... But, still not working correctly. Here is the output: Array -- Array -- Array from: ?php include db.inc.back.php; foreach ($_FILES[pictures][error] as $key = $error) { if ($error == UPLOAD_ERR_OK) { echo $error_codes[$error]; move_uploaded_file( $_FILES[pictures][tmp_name][$key], bikeimages/ .$_FILES[pictures][name][$key] ) or die(Problems with upload); ${image.($key+1)} = $_FILES['pictures']['name']; } } $make = $_POST['make']; $model = $_POST['model']; $year = $_POST['year']; $color = $_POST['color']; $description = $_POST['description']; //$image1 = $_POST['image1']; //$image2 = $_POST['image2']; //$image3 = $_POST['image3']; $status = $_POST['status']; echo $image1 -- $image2 -- $image3; /* $query = INSERT INTO `inventory` (`make`, `model`, `year`, `color`, `description`, `image1`, `image2`, `image3`, `status`) VALUES ('$make', '$model', '$year', '$color', '$description', '$image1', '$image2', '$image3', '$status');; $result = mysql_db_query($db, $query) or displayErrorQuery ($query); echo meta http-equiv='refresh' content='0;URL=inventorylist.php'; exit; */ ? smime.p7s Description: S/MIME cryptographic signature
RE: [PHP-DB] Arrays from forms....
I know you really meant : ${image.($key+1)} = $_FILES['pictures']['name'][$key]; And it works!!! Thanks oh so very much! -Original Message- From: Chris [mailto:[EMAIL PROTECTED] Sent: Thursday, November 30, 2006 11:46 PM To: Gary E. Terry Cc: php-db@lists.php.net Subject: Re: [PHP-DB] Arrays from forms Gary E. Terry wrote: OK.. I am a moron.. Forgot that I had changed the name of the field in the form, and got sidetracked and didn't change it in the php... But, still not working correctly. Here is the output: Array -- Array -- Array Oops this: ${image.($key+1)} = $_FILES['pictures']['name']; should be: ${image.($key+1)} = $_FILES['pictures'][$key]['name']; -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php smime.p7s Description: S/MIME cryptographic signature