에 삽입되지 않은 :데이터 테이블
이<?php
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
die();
}
$result = 0;
//UPLOAD IMAGE FILE
move_uploaded_file($_FILES["fileImage"]["tmp_name"], "ImageFiles/" . $_FILES["fileImage"]["name"]);
$result = 1;
//INSERT INTO IMAGE DATABASE TABLE
$imagesql = "INSERT INTO Image (ImageFile) VALUES (?)";
if (!$insert = $mysqli->prepare($imagesql)) {
// Handle errors with prepare operation here
}
//Dont pass data directly to bind_param store it in a variable
$insert->bind_param("s", $img);
//Assign the variable
$img = 'ImageFiles/' . $_FILES['fileImage']['name'];
$insert->execute();
$insertimagequestion->execute();
//IF ANY ERROR WHILE INSERTING DATA INTO EITHER OF THE TABLES
if ($insert->errno) {
// Handle query error here
}
$insert->close();
$lastID = $mysqli->insert_id;
$imagequestionsql = "INSERT INTO Image_Question (ImageId, SessionId, QuestionId)
VALUES (?, ?, ?)";
if (!$insertimagequestion = $mysqli->prepare($imagequestionsql)) {
// Handle errors with prepare operation here
echo "Prepare statement err";
}
$sessid = $_SESSION['id'] . ($_SESSION['initial_count'] > 1 ? $_SESSION['sessionCount'] : '');
$insertimagequestion->bind_param("isi",$lastID, $sessid, $_POST['numQuestion'][$i]);
$insertimagequestion->execute();
if ($insertimagequestion->errno) {
// Handle query error here
}
$insertimagequestion->close();
}
?>
그래서 예를 들어 나는이 개 이미지를 삽입하는 경우 "cat.png "와"이미지 "데이터베이스 테이블"로 "dog.png,이처럼 삽입합니다 :
ImageId ImageFile
220 cat.png
221 dog.png
(ImageId is an auto increment)
을 어쨌든 제가하고 싶은 것은 파일이 업로드 될 때뿐만 아니라 데이터가 삽입되어 있다는 것입니다 위의 표를 참조하십시오. 그러나 위에 삽입 된 ImageId를 검색하여 아래의 'Image_Question'표에 배치 할 수 있기를 바랍니다. 그래서 다음과 같을 것입니다 :
ImageId SessionId QuestionId
220 AAA 1
221 AAB 4
그러나 Image_Question 테이블에는 아무 것도 삽입하지 않습니다. 이미지를 업로드 할 때 "이미지"테이블에 데이터를 삽입 할뿐만 아니라 "Image_Question"테이블에도 데이터를 삽입 할 수 있습니까?
내가 해제 방법이야 경우
오류가 있습니까? '$ insert-> close()'가 아마 유효하지 않은 것 같습니다. –
PHP 오류 보고서에서 오류가 없습니다. – user1681039