I'm trying to to append images references to columns image1-4 in my database, instead I'm getting the images uploaded x3 times each and with random references in phpmyadmin.
<?php
$user_name = "root";
$user_pass = "";
$host_name = "localhost";
$db_name = "melony";
$con = mysqli_connect($host_name, $user_name, $user_pass, $db_name);
if($con)
{
$image = $_POST['image'];
$name = $_POST['name'];
$lat = (float) $_POST['lat'];
$lng = (float) $_POST['lng'];
for($i=1; $i<5; $i=$i+1){
$now = DateTime::createFromFormat('U.u', microtime(true));
$id = $now->format('YmdHisu');
$upload_path = "uploads/$id.jpeg";
$sql = "insert into uploads(name,lat,lng,image,image2,image3,image4) values
('$name','$lat','$lng','$upload_path','a','a','a')ON DUPLICATE KEY UPDATE
image$i = '$upload_path'";
if(mysqli_query($con,$sql))
{
file_put_contents($upload_path,base64_decode($image));
echo json_encode(array('response'=>'Image Upload Successfully'));
}
else
{
echo json_encode(array('response'=>'Image upload failed1,
mysqli_error($con)'));
}
}
}
else
{
echo json_encode(array('response'=>'Image Upload Failed2'));
}
mysqli_close($con);
?>