I am looking for some help I am having a page where I input images but in that page the number of images that are inputted it's generated as a loop so if the user chooses 2 he will have to enter 2 images and if 3 -> 3 images . The problem here is when I try to upload those images on my database Mysql
the code:
<div id="chambres" class="chambres">
</div>
<script type="text/javascript">
//Here a js code that generat a script as a loop and it gives classes and inputes differents like :
<input name='nbr_max_chambre" + (i+1) + "' class='h_input' type='text'>
</script>
here is the code to move the image to my folder
for($i = 1; $i <= $nbr_chambre; $i++) {
${"nbr_max_chambre$i"} = $_POST["nbr_max_chambre$i"];
${"prix_cham$i"} = $_POST["prix_cham$i"];
${"desc_chambre$i"} = $_POST["desc_chambre$i"];
// image chambre //
// ${"img_chambre$i"+"_name"} = $_FILES["img_chambre$i"];
// ${"img_chambre"+ $i +"_name"} = $_FILES["img_chambre$i"]["name"];
if(isset($_FILES["img_chambre$i"])){
$imgname = $_FILES["img_chambre$i"]["name"];
// ${"img_chambre$i"+"size"} = $_FILES["img_chambre$i"]['size'];
$imgsize = $_FILES["img_chambre$i"]['size'];
// ${"img_chambre$i"+"_tmp_name"} = $_FILES["img_chambre$i"]['tmp_name'];
$imgtmp = $_FILES["img_chambre$i"]['tmp_name'];
// ${"img_chambre$i"+"error"} = $_FILES["img_chambre$i"]['error'];
$imgerror = $_FILES["img_chambre$i"]['error'];
}
if ($imgerror === 0) {
if ($imgsize > 1250000) {
$em = "Sorry, your file is too large.";
header("Location: Registration_locataire.php?error=$em");
}else {
$img_ex = pathinfo($imgname, PATHINFO_EXTENSION);
$img_ex_lc = strtolower($img_ex);
$allowed_exs = array("jpg", "jpeg", "png");
if (in_array($img_ex_lc, $allowed_exs)) {
${"new_img_chambre$i"+"_name"} = uniqid("IMG-", true).'.'.$img_ex_lc;
$img_upload_path = 'image/'.${"new_img_chambre$i"+"_name"};
move_uploaded_file($imgtmp, $img_upload_path);
}else {
$em = "You can't upload files of this type";
echo $em;
// header("Location: add_house.php");
}
}
}else {
$em = "unknown error occurred!";
echo $em;
// header("Location: add_house.php");
}
${"etage_selection$i"} = $_POST["etage_selection$i"];
}
and here is the code when I try to upload it in the database :
for($i = 1; $i <= $nbr_chambre; $i++) {
${"ID_CHAM$i"} = rand(time(), 100000000);
${"requete_cham$i"} = $bd->prepare('INSERT INTO chambres values (?,?,?,?,?,?,?,?)');
${"requete_cham$i"}->bindValue(1,${"ID_CHAM$i"});
${"requete_cham$i"}->bindValue(2,$ID_MAISON);
${"requete_cham$i"}->bindValue(3,NULL);
// ${"requete_cham$i"}->bindValue(4,${"nbr_max_chambre$i"});
${"requete_cham$i"}->bindValue(4,2);
${"requete_cham$i"}->bindValue(5,NULL);
${"requete_cham$i"}->bindValue(6,${"desc_chambre$i"});
${"requete_cham$i"}->bindValue(7,${"etage_selection$i"});
// ${"requete_cham$i"}->bindValue(8,${"new_img_chambre$i"+"_name"});
${"requete_cham$i"}->bindValue(8,NULL);
${"requete_cham$i"}->execute();
}
but the problem is the variable: ${"new_img_chambre$i"+"_name"}
is not working the image is not uploaded even when I try to do echo to the name of the image echo ${"new_img_chambre$i"+"_name"}
it's not working I wish if there is someone to help me and thank you so much.