if($_REQUEST['subview']=="add")

   {

          $title = mysqli_real_escape_string($db->conn,$_POST['title']);

          $cat_id = mysqli_real_escape_string($db->conn,$_POST['category']);

          $area = mysqli_real_escape_string($db->conn,$_POST['area']);

          $bedroom = mysqli_real_escape_string($db->conn,$_POST['bedroom']);

          $bathroom = mysqli_real_escape_string($db->conn,$_POST['bathroom']);

          $garage = mysqli_real_escape_string($db->conn,$_POST['garage']);

          $content=mysqli_real_escape_string($db->conn,$_POST['text']);

          $data = array("title"=>$title,

                         "cat_id"=>$cat_id,

                         "area"=>$area,

                         "bedroom"=>$bedroom,

                         "bathroom"=>$bathroom,

                         "garage"=>$garage,

                         "content"=>$content,

                        "status"=>"active",

                        "added_date"=>date("Y-m-d H:i:s", time())

             );

          if($db->insert($data,'bk_property') == true)  

            {

            $last_id = mysqli_insert_id($db->conn);

            if($_FILES['image']['name']!="")

                 {

                    $check = getimagesize($_FILES["image"]["tmp_name"]);

    if($check !== false) {

                   $image = $_FILES['image']['name'];

                   $exp = explode(".",$image);

                   $extension = end($exp);

                   $image_name = "property_".$date.".".$extension;

                    $upload = move_uploaded_file($_FILES['image']['tmp_name'],"../aboutus/".$image_name);

                    if($upload)

                      {

                        $thumbnail = $obj->generateThumbnail("../aboutus/".$image_name, "../aboutus/thumb/".$image_name, 370, 250);

                        $sql2 = "UPDATE bk_property SET image_name='".$image_name."' WHERE id='".$last_id."'";

                        $update_image = mysqli_query($db->conn,$sql2) or die(mysqli_connect_errno()."Data cannot inserted");

                      }

                      }

  else {

        $_SESSION['property'] = "File is Not an image!";

            echo "<script>window.location.href='../properties.php?subview=list'</script>"; 

       }  

                 }

            $_SESSION['property'] ="Added Success Fully.";

            echo "<script>window.location.href='../properties.php?subview=list'</script>";    

            }

          else

            {

            $_SESSION['property'] ="Image couldn't be added.Please try again.";

            echo "<script>window.location.href='../properties.php?subview=add'</script>";   

            }   

   }

``

Dani AI

Generated

Short summary and concrete fixes following the thread: 's snippet only ever writes one filename into bk_property, so multiple uploads never get recorded. is right — there is no loop — and 's pointer to the PHP manual is the right direction. The typical changes needed are: (1) HTML/form must use enctype="multipart/form-data" and input named as image[] with the multiple attribute; (2) server-side must treat $_FILES['image'] as an array and loop its members; (3) database schema should store many images per property (not a single image_name column).

Suggested image-table schema (example):

CREATE TABLE bk_property_images (
  id INT AUTO_INCREMENT PRIMARY KEY,
  property_id INT NOT NULL,
  image_name VARCHAR(255) NOT NULL,
  is_primary TINYINT(1) DEFAULT 0,
  added_date DATETIME DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (property_id) REFERENCES bk_property(id) ON DELETE CASCADE
);

Example handling pattern (illustrative):

$stmt = $db->conn->prepare("INSERT INTO bk_property_images (property_id,image_name) VALUES (?,?)");
foreach ($_FILES['image']['name'] as $i => $orig) {
  $tmp  = $_FILES['image']['tmp_name'][$i];
  $err  = $_FILES['image']['error'][$i];
  if ($err !== UPLOAD_ERR_OK) continue;
  if (getimagesize($tmp) === false) continue;
  $ext = pathinfo($orig, PATHINFO_EXTENSION);
  $new = "property_{$last_id}_" . time() . "_{$i}.{$ext}";
  if (move_uploaded_file($tmp, $targetDir . $new)) {
    $stmt->bind_param("is",$last_id,$new);
    $stmt->execute();
  }
}

Troubleshooting notes and cautions: confirm max_file_uploads, upload_max_filesize, and post_max_size in php.ini (use phpinfo() or ini_get()); check upload directory permissions and available disk space; always validate files (mime/type + getimagesize) and sanitize/unique-ify filenames (the snippet uses $date which may be undefined — use time() or uniqid() instead). For security, use prepared statements, restrict accepted extensions, store uploads outside webroot or deny execution via server rules, and log $_FILES['image']['error'] codes to diagnose failures.

Recommended Answers

All 2 Replies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.