초보 안드로이드 개발하는 사람입니다.
안드로이드에서 php로 데이터를 넘겨서 서버에 파일을 만들고 MySQL에도 insert 하려고 하는데,
서버에 파일은 1개씩만 잘 만들어 지는데 MySQL에서 2개씩 중복이 되서 들어갑니다.
예를 들어
이미지1.jpg 이미지2.jpg 이미지3.jpg 이미지1.jpg 이미지2.jpg 이미지3.jpg 이런 식으로 들어갑니다.
혹시 무슨 문제가 있는지 알 수 있을까요?
파일을 서버 폴더에 넣는 코드랑 DB에 넣는 코드는 이렇습니다.
for ($i = 0; $i < $NumOfImages; $i = $i + 1) {
if (file_put_contents($path . "/{$ProductName}" . "_" . ($i+1) . ".jpeg", base64_decode($obj["Count".($i+1)]))) {
$imageName = $ProductName . "_" . ($i + 1);
if ($stmt = $conn->prepare("INSERT INTO images (imageName, ProductName, FilePath) VALUES (?, ?, ?)")) {
$stmt->bind_param(
"sss",
$imageName,
$ProductName,
$path
);
$stmt->execute();
}
} else {
printf("The content is not exist");
$response["success"] = false;
}
}
if ($stmt = $conn->prepare("INSERT INTO product (
ProductName,
ProductDesc,
ProductPrice,
ProductOwner,
tradeLocation,
AddedDate)
VALUES (
?,
?,
?,
?,
?,
?)")
) {
$stmt->bind_param(
"ssssss",
$ProductName,
$ProductDesc,
$productPrice,
$productOwner,
$Location,
$AddedDate
);
$stmt->execute();
$response["success"] = true;
}
echo json_encode($response);