它给了我这个错误,谁能帮帮我?(!)分析错误:语法错误,第59行的C:\wamp64\www\photogallery\includes\gallery-upload.inc.php中出现意外的'else‘(T_ELSE)
她是我的密码,希望你能帮我。我找不到我的错误。现在有没有人能回答我考试需要用到它,大概需要2个小时。
$newFileName = $_POST['filename'];
if(empty(empty($newFileName))) {
$newFileName = "gallery";
} else {
$newFileName = strtolower(str_replace(" ", "-", $newFileName));
}
$imageTitle = $_POST['filetitle'];
$imageDesc = $_POST[''];
$file = $_FILES['file'];
$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 = $newFileName ."." . uniqid("", true) ."." . $fileActualExt;
$fileDestination = "../img/gallery/" . $imageFullName;
include_once "dbh.inc.php";
if (empty($imageTitle) || empty($imageDesc)) {
header("Location: ../gallery.php?upload=empty");
exit();
} else {
$sql = "SELECT * FROM gallery";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL statement failed!";
} else {
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$rowCount = mysqli_num_rows($result);
$setImageOrder = $rowCount + 1;
$sql = "INSERT INTO gallery (titleGallery, descGallery, imgFullNameGallery, orderGallery) VALUES (?, ?, ?, ?);";
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL statement failed!";
} else {
mysqli_stmt_bind_param($stmt, "ssss", $imageTitle, $imageDesc, $imageFullName, $setImageOrder);
mysqli_stmt_execute($stmt);
move_uploaded_file($fileTempName, $fileDestination);
header("Location: ../gallery.php?upload=succes");
}
}
} else {
echo "File size is to big";
exit();
} else {
echo "You had an error!";
exit();
} else {
echo "You need to upload a proper file type!";
exit();
}
} ?>
发布于 2018-12-13 06:02:37
这个错误意味着在ELSE语句之前缺少了一些东西。它说的是unexpected 'else'
,这意味着它在else
之前期待的是其他东西。
代码很可能在前一行缺少分号或右大括号。但是,如果您在gallery-upload.inc.php
文件的第59行附近发布代码,我们可以为您提供更明确的答案。你从哪里得到这个文件的?
发布于 2018-12-13 08:16:36
我不认为你可以使用多个会导致上述错误的方法。
错误码:
if (condition) {
echo 'test';
} else {
echo "File size is to big";
exit();
} else {
echo "You had an error!";
exit();
} else {
echo "You need to upload a proper file type!";
exit();
}
对条件使用else-if。
if (condition) {
//something
} else if (condition) {
//something
} else {
//something
}
希望这能有所帮助!Tq
https://stackoverflow.com/questions/53754075
复制相似问题