I used the following code to add multiple images to my database through the admin area of my website, this works fine, but I want to display the multiple images that were uploaded for that specific vehicle id... Basically I'm trying to create a website for a car dealer, when the admin is adding stock they can choose multiple images to add to the listing, here is the add stock code
<?php
if(isset($_POST['addstock'])){
$vehicle_make = $_POST['vehicle_make'];
$veh_model = $_POST['veh_model'];
$veh_mileage = $_POST['veh_mileage'];
$veh_description = $_POST['veh_description'];
$veh_price = $_POST['veh_price'];
$veh_gearbox = $_POST['veh_gearbox'];
$veh_engine_size = $_POST['veh_engine_size'];
$veh_fuel_type = $_POST['veh_fuel_type'];
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
$file_name = $key.$_FILES['files']['name'][$key];
$file_size = $_FILES['files']['size'][$key];
$file_tmp = $_FILES['files']['tmp_name'][$key];
$file_type = $_FILES['files']['type'][$key];
$addstock = "insert into stock (veh_make,veh_model,veh_mileage,veh_description,veh_gearbox,veh_engine_size,veh_fuel_type,veh_price,file_name,file_size,file_type) values('$vehicle_makee','$veh_model','$veh_mileage','$veh_description','$veh_gearbox','$veh_engine_size','$veh_fuel_type','$veh_price','$file_name','$file_size','$file_type')";
move_uploaded_file($file_tmp,"image_uploads/".$file_name);
}
$addsto = mysqli_query($con, $addstock);
if($addsto){
echo "<script>alert('Vehicle has been added')</script>";
echo "<script>window.open('addstock.php','_self')</script>";
}
}
The code succesfully adds multiple images to the directory folder,
Here is the code outside the admin area, on the vehicle details page, only 1 images displays out of the multiple images I uploaded, I want all images to be displayed that were uploaded for the vehicle ID, eventually this will be styled into an image gallery,
<?php
if(isset($_GET['vehicle_id'])){
$vehicle_id = $_GET['vehicle_id'];
$get_veh = "select * from stock where vehicle_id='$vehicle_id'";
$run_veh = mysqli_query($con, $get_veh);
while($row_veh=mysqli_fetch_array($run_veh)){
$vehicle_id = $row_veh['vehicle_id'];
$veh_make = $row_veh['veh_make'];
$veh_model = $row_veh['veh_model'];
$veh_mileage = $row_veh['veh_mileage'];
$veh_price = $row_veh['veh_price'];
$veh_gearbox = $row_veh['veh_gearbox'];
$veh_description = $row_veh['veh_description'];
$file_name = $row_veh['file_name'];
echo "
<div id='single_vehicle'>
<div id='box1'>$veh_make $veh_model</div>
<div id='box3'>£$veh_price</div>
</div>
<div id='single_vehicle2'>
<div id='box2'><img src='admin/image_uploads/$file_name' width='600' height='450' /></div>
<div id='box4'>
<div id='clickbox1'><a href='#'>Book Test Drive</a></div>
<div id='clickbox1'><a href='#'>Send Enquiery</a></div>
<div id='clickbox1'><a href='#'>Print this Page</a></div>
<div id='clickbox1'><a href='#'>Email this Page</a></div>
</div>
</div>
<div id='desription_area'>
<div id='desription_area1'><span style='text-decoration:underline'>Vehicle Description</span><br>$veh_description</div>
<div id='desription_area2'><span style='text-decoration:underline'>Specification</span><br>Make: $veh_make<br>$veh_model<br>$veh_mileage</div>
</div>
";
}
}
?>
I'm new to coding and still learning, what have I done wrong? Any help is much appreciated