我正在尝试将一些数据上传到我的网站中。我尝试上传的图像已上传到我的图像文件夹中,但数据库没有输入数据。它在mysqli_stmt_bind_param
中显示错误。我找不到错误。
有人可以帮我吗?
if (isset($_POST['submit1'])) {
$cakename = $_POST['cakeName'];
$Beschreibung = $_POST['beschreibung'];
$Preis = $_POST['preis'];
$file = $_FILES['image'];
$fileName = $file["name"];
$filetype = $file["type"];
$fileTempName = $file["tmp_name"];
$fileError = $file["error"];
$fileSize = $file["size"];
$fileExt = explode(".", $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array("jpg", "jpeg", "png");
if (in_array($fileActualExt, $allowed)) {
if ($fileError === 0) {
if ($fileSize < 2000000) {
$imageFullName = $cakename.".". uniqid("", true).".". $fileActualExt;
$fileDestination = "../Bake_my_cake1/image/".$imageFullName;
include_once 'lib/db_connector.php';
$db = dbconnect();
if (empty($Beschreibung) || empty($Preis)) {
header("Location: ../Bake_my_cake1/Profile_baker1.php?upload=empty");
exit();
} else {
$sql = "SELECT * FROM Cake;";
$stmt = mysqli_stmt_init($db);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL statement failed 1";
} else {
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$rowCount = mysqli_num_rows($result);
$setImageOrder = $rowCount + 1;
$sql = "INSERT INTO Cake (CakeName, Beschreibung, Preis, orderGallery) VALUES(?, ?, ?, ?);";
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL statement failed 2";
} else {
mysqli_stmt_bind_param($stmt, "ssss", $imageFullName, $Beschreibung, $Preis, $setImageOrder);
mysqli_stmt_execute($stmt);
echo "error 1";
move_uploaded_file($fileTempName, $fileDestination);
header("Location ../Bake_my_cake1/Profile_baker1.php?upload=sucess");
}
}
}
dbclose($db);
} else {
echo"File Size is too Big";
exit();
}
} else {
echo"You have an error";
exit();
}
} else {
echo"You need to upload a proper file type";
exit();
}
}
?>
else{
mysqli_stmt_bind_param($stmt,"ssss", $imageFullName, $Beschreibung, $Preis, $setImageOrder);
mysqli_stmt_execute($stmt);
echo "error 1";
move_uploaded_file($fileTempName,$fileDestination);
header("Location ../Bake_my_cake1/Profile_baker1.php?upload=sucess");
它显示错误1。
答案 0 :(得分:0)
根据您的变量名,我假设您的函数dbconnect()
返回数据库对象。并且您正在$db
中传递那个mysqli_stmt_init
而不是数据库连接对象。
例如。
如果您要返回数据库连接对象并将其存储在$con
中,那么您的代码将类似于$stmt = mysqli_stmt_init($con)
。
使用此代码,您不会看到"SQL statement failed 1"
消息,并且您的代码将按预期执行。