Dear all, whenever I want to edit other inputs like images in the snippet of codes below the array of input in size select input always wipe off if I don’t reinsert the sizes that I choose initially in it because it is an array element.
Please, how can I make it stiky if I don’t re-choose the same sizes I entered while inserting the product.
<form>
<select name="size[]" multiple="multiple" style="height:150px;" class="form-control"><option value="<?php echo $size; ?>"> <?php echo $size; ?> </option>
<?php
$get_sizes = "select * from sizes";
$run_sizes = mysqli_query($con,$get_sizes);
while ($row_sizes=mysqli_fetch_array($run_sizes)){
$size_id = $row_sizes['size_id'];
$size = $row_sizes['size'];
echo "
<option value='$size'> $size </option>
";
}
?>
</select><!-- form-control Finish -->
<?php
if(isset($_POST['update'])){
$product_title = mysqli_real_escape_string($con, trim($_POST['product_title']));
$product_url =mysqli_real_escape_string($con, trim($_POST['product_url']));
$product_cat = $_POST['product_cat'];
$product_cat = implode(", ", $product_cat);
$cat = mysqli_real_escape_string($con, trim($_POST['cat']));
$size = $_POST['size'];
$size = implode(", ", $size);
$manufacturer_id = mysqli_real_escape_string($con, trim($_POST['manufacturer']));
$product_price = (INT) $_POST['product_price'];
$product_keywords = mysqli_real_escape_string($con, trim($_POST['product_keywords']));
$product_desc = mysqli_real_escape_string($con, trim($_POST['product_desc']));
$product_features = mysqli_real_escape_string($con, trim($_POST['product_features']));
$product_video = $_POST['product_video'];
$product_seo = mysqli_real_escape_string($con, trim($_POST['seo_keywords']));
$product_sale = mysqli_real_escape_string($con, trim($_POST['product_sale']));
$product_label = mysqli_real_escape_string($con, trim($_POST['product_label']));
if(is_uploaded_file($_FILES['product_img1']['tmp_name']) || ($_FILES['product_img2']['tmp_name']) || ($_FILES['product_img3']['tmp_name'])){
// work for upload / update image
$product_img1 = $_FILES['product_img1']['name'];
$product_img2 = $_FILES['product_img2']['name'];
$product_img3 = $_FILES['product_img3']['name'];
$temp_name1 = $_FILES['product_img1']['tmp_name'];
$temp_name2 = $_FILES['product_img2']['tmp_name'];
$temp_name3 = $_FILES['product_img3']['tmp_name'];
move_uploaded_file($temp_name1,"product_images/$product_img1");
move_uploaded_file($temp_name2,"product_images/$product_img2");
move_uploaded_file($temp_name3,"product_images/$product_img3");
$update_product = "update products set p_cat_id='$product_cat',cat_id='$cat',size='$size',manufacturer_id='$manufacturer_id',date=NOW(),product_title='$product_title',product_url='$product_url',product_img1='$product_img1',product_img2='$product_img2',product_img3='$product_img3',product_keywords='$product_keywords',product_desc='$product_desc',product_price='$product_price',product_sale='$product_sale',product_label='$product_label',product_features='$product_features',product_video='$product_video' where product_id='$p_id'";
$run_product = mysqli_query($con,$update_product);
if($run_product){
echo "<script>alert('Your product has been updated Successfully')</script>";
echo "<script>window.open('index.php?view_products','_self')</script>";
}
}else{