Language: PHP / MySQL
I have a form on a page, with hidden inputs. I forward the data from these inputs on to another page, then I insert them into my database.
The inputs inside the form are:
- copied_filename[]
- copied_url[]
- copied_userid[]
These are set-up to be arrays because there are times that a user will have more than one file attached.
<input type="hidden" id="copied_filename" name="copied_filename[]" value="<?php echo $img->filename; ?>" />
<input type="hidden" id="copied_url" name="copied_url[]" value="<?php echo $img->url; ?>" />
<input type="hidden" id="copied_userid" name="copied_userid[]" value="<?php echo $current_user->id; ?>" />
Now on the 2nd page where the data is received, this is how I handle it:
if (empty($_POST["copied_filename"])) {
WHAT IT DOES WHEN THERE ARE NO ATTACHED FILES
}
else {
$copied_filename = $_POST["copied_filename"];
$copied_url = $_POST["copied_url"];
$new_sessionid = $_POST['session_id'];
foreach ($_POST["copied_filename"] as $copied_file) {
$sql = "INSERT INTO ".$wpdb->prefix."estimate_images (code, url, filename, session_id, user_id) VALUES ('".$code."', '".$copied_url."', '".$copied_file."','".$new_sessionid."', '".$current_user->id."')";
$wpdb->query($sql);
}
It works fine for the filename, but the URL being inserted in my database is the word “Array“…
I am sure it is the foreach format, but I am stumped & don’t know how to fix it.
Thank you so much for your time, any assistance would be greatly appreciated!
1 Answer