So basically what I want to do is to grab the selected checklist element(s) and send their “name” to the database. I would also like to do the same with the radios. Here is the code:
<?php
$user_files_directory = 'uploads/unused_images/'.$_SESSION['user_id'].'/';
if (file_exists($user_files_directory)) {
$dir_handle = @opendir($user_files_directory);
while ($file = readdir($dir_handle)) {
if($file == "." || $file == ".." || $file == "index.php" )
continue;
echo "
<div id=\"image_container\">
<div id=\"unused_images_selector\">
<img src=\"uploads/thumbs/unused_images/".$_SESSION['user_id']."/$file\" alt=\"Test\">
</div>
<div id=\"checkbox\">
<input type=\"checkbox\" name=\"$file\">
</div>
</div>
";
}
// Close
closedir($dir_handle);
} else {
echo "<p>
You have not uploaded any images.
</p>";
}
?>
A post for this exists:
$file = $_POST['file'];
And here is the rest:
function create_new_page($page_name, $album_name, $file, $file1, $file2) {
$page_name = mysql_real_escape_string(htmlentities($page_name));
mysql_query("INSERT INTO `pages` VALUES ('', '$album_name', '".$_SESSION['user_id']."', UNIX_TIMESTAMP(), '$page_name', '$file2', '$file3', '$file')");
return mysql_insert_id();
}
Everything but the radio/checklist works, any help is greatly appreciated, I know the code may not be the best but that’s because I’ve not done much PHP, just want some working code though so not worried too much right now about issues here and there.
EXTRA: $file is the name of the images that are being placed in the page (it’s a selection area for which images a user would like to use) and so I was hoping that, with using $file it would create the image name in the MYSQL database but it instead writes “array”.
You have misunderstood the workings of a HTML form and the way to extract it in PHP.
You are setting the
nameattribute to the actual file name (which is not “file”) and are trying to extract the POST param with namefile. The way to do this would be to name the checkboxfile[](as in an array of files) and set thevalueattribute to the file name. Your PHP code may remain the same.Modify your checkbox code as follows:
Since you already have the following:
$filewill give you an array of file names. You can then process that data as you require.EDIT : Since the OP has modified the question.
You want to store multiple image names into the database so you need to fire multiple
INSERTstatements. You could probably loop on the$filevariable and build your queries.Use something on the following lines: