I want to upload Multiple Images for a particular listing into the PROPERTYIMAGES Column/Field of my PROPERTIES Table. I've a working code though,it stores the images in the appropriate UPLOADS folder, But the problem is in the Database. It ends up inserting 3 listings into the Table which corresponds with the THREE IMAGES selected for that LISTING with .
However i want to insert just one Row in the database then for the 'propertiesImages', I want all 3 images path to be stored into one column. I don't know if i'm saying this rigth, I just wish someone will understand.
I'll drop the codes and possibly Image Snapshots
///PHP CODE TO INSERT RECORDS//
<?php
session_start();
include "../incs/database/dbconfig.php"; //include the DB config file
if (isset($_POST['propertyTitle']) && isset($_SESSION['userid']) && $_SESSION['userid'] == true) {
//Retrieve Form Data From AJAX Parsing
$title = mysqli_real_escape_string($dbconn, $_POST['propertyTitle']);
$desc = mysqli_real_escape_string($dbconn, $_POST['propertyDescription']);
$pType = mysqli_real_escape_string($dbconn, $_POST['propertyType']);
$pStatus = mysqli_real_escape_string($dbconn, $_POST['propertyStatus']);
$pLocation = mysqli_real_escape_string($dbconn, $_POST['propertyLocation']);
$pMainLocation = mysqli_real_escape_string($dbconn, $_POST['mainLocation']);
$bedrooms = mysqli_real_escape_string($dbconn, $_POST['bedroomNumber']);
$bathrooms = mysqli_real_escape_string($dbconn, $_POST['bathroomNumber']);
$garage = mysqli_real_escape_string($dbconn, $_POST['garageNumber']);
$pNumber = mysqli_real_escape_string($dbconn, $_POST['propertyNumber']);
$pPrice = mysqli_real_escape_string($dbconn, $_POST['propertyPrice']);
$pAreaSize = mysqli_real_escape_string($dbconn, $_POST['propertyAreaSize']);
$pAreaPFT = mysqli_real_escape_string($dbconn, $_POST['areaPostfixText']);
$pVideo = mysqli_escape_string($dbconn, $_POST['propertyVideoURL']);
$features = "";
foreach($_POST['propertyFeatures'] as $feature) {
// Here $results holding all the check box values as a string
$features .= $feature. ",";
}
$propertyAuthor = mysqli_real_escape_string($dbconn, $_SESSION['userid']);
for($i = 0; $i < count($_FILES['propertyImages']['name']); $i++) {
$imageTempDirectory = $_FILES["propertyImages"]["tmp_name"][$i];
$imageName = $_FILES["propertyImages"]["name"][$i];
$filetype = $_FILES["propertyImages"]["type"][$i];
$pathForImageUpload = "uploads/".$imageName;
move_uploaded_file($imageTempDirectory,$pathForImageUpload);
//Submit Properties Data in Propertires Table
$propertyKwary = mysqli_query($dbconn, "INSERT INTO properties (propertyTitle,propertyDescription,pTid,pSid,pLid,mainLocation,bedroomNumber,bathroomNumber,garageNumber,propertyNumber,propertyPrice,propertyAreaSize,propertyAreaSizePostfix,propertyVideoUrl,propertyFeatures,uid,propertyImages,submittedDate) VALUES ('$title','$desc','$pType','$pStatus','$pLocation','$pMainLocation','$bedrooms','$bathrooms','$garage','$pNumber','$pPrice','$pAreaSize','$pAreaPFT','$pVideo','$features','$propertyAuthor','$pathForImageUpload',NOW())");
if ($propertyKwary) {
// echo'<script>alert("Property Submission Failed-"'. mysqli_error($dbconn). ')</script>';
echo 'Property Submitted Successfully';
// header("Location: submit-listing.php");
} else {
echo 'Property Submission Failed';
}
}
}
// HTML FORM INPUT//
<input type="file" name="propertyImages[]" id="propertyImages" multiple accept=".jpg, .png, .jpeg" />
<br><br>
<div id="propertyImagesPreview"></div>