0

It gives me this error could anyone help me please? ( ! ) Parse error: syntax error, unexpected 'else' (T_ELSE) in C:\wamp64\www\photogallery\includes\gallery-upload.inc.php on line 59

Her is my code I hope you can help me. I couldn't find my error. Could someone answer now I need it for my exam and that's about 2 hours.

$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();
    }

} ?>

2 Answers2

0

This error means that there is something missing immediately before the ELSE statement. It says unexpected 'else' which means that it was expecting something else before the else.

It is likely that the code is missing a semi-colon or closing brace on the previous line. However, if you post your code around line 59 of the gallery-upload.inc.php file we can provide you with a more definite answer. Where did you get this file from?

kojow7
  • 10,308
  • 17
  • 80
  • 135
0

I don't think you can use multiple else which result in the above error.
Error code:

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();
}  

Use else-if with the condition.

if (condition) {
   //something
} else if (condition) {
   //something
} else {
   //something
}

Hope this helps! Tq

Revathi Ganesh
  • 119
  • 1
  • 6