Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an error within this PHP else if statement (which is part of an if statement):

Parse error: syntax error, unexpected '}' in /home1/tony1964/public_html/2v2tournaments/action.php

The place where the unexpected '}' is at the end of the code below. I can't figure out why this doesn't work. Thanks in advance for any help.

    else if (isset($_GET['do']) && $_GET['do'] === "reg_type_2") {

        include('php-riot-api.php');
        $summoner_name_input = $_POST['summonername'];
        $summoner_name = str_replace(' ', '_', $summoner_name_input);
        $summoner_region = $_POST['summonerregion'];
        $verify_code_input = $_POST['verify_code'];
        $verify_code = str_replace(' ', '_', $verify_code_input);
        $instance = new riotapi($summoner_region);
        $grab_data = $instance->getSummonerByName($summoner_name);
        $decode_data = json_decode($grab_data);
        $grab_id = $decode_data->{'id'};
        var_dump($grab_id);
        $grab_runes = $instance->getSummoner($grab_id,'runes');
        $decode_runes = json_decode($grab_runes);
        $rune_check = $decode_runes->{'name'};

        if ($rune_check = $verify_code) {
            $logged_user = $_SESSION['logged_user'];

        if (!($stmt  = $con->prepare("INSERT INTO `verified_summoners`   (`Username`,`SummonerName`,`SummonerRegion`) VALUES (?,?,?)")) || !is_object($stmt)) {
            die( "Error preparing: (" .$con->errno . ") " . $con->error);
        }

        $stmt->bind_param('sss', $logged_user, $summoner_name, $summoner_region);

        if($stmt->execute()) { 
            echo "Successfully Verified! Check out your new list! <a class='content' href='index.php'><span class='button color_yellow'>Return</span></a>";

        } else {
            echo "Unsuccessful INSERT, Contact Support or Try again...";
        }

        $stmt->close();
    }

} else {

    echo "O Dear, It didn't work! Try Again!";
}

}

share|improve this question

closed as off-topic by Marc B, j08691, LittleBobbyTables, meda, David Jan 30 at 14:40

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Marc B, j08691, LittleBobbyTables, meda, David
If this question can be reworded to fit the rules in the help center, please edit the question.

3  
If you'd bothered to properly indent your code, you'd probably be able to see where the unbalanced { and } are... This is obviously just a simple typo, so voting to close. –  Marc B Jan 30 at 14:37
    
The code is indented in dreamweaver, I removed the indents as I tend to get complaints when i do indent. –  Night Jan 30 at 14:41
    
@Night you get complaints when you indent?!? I find this hard to believe, as not only would you of spotted the error very easily if the code was correctly formatted, but I can't believe someone complains to you for correctly formatting code. –  Ryan Jan 30 at 14:42
    
@Ryan probably because people don't like scrolling horizontally when looking at questions. @Night The extra } removed from @Ryan's answer should do the trick. –  Vincent Wilkie Jan 30 at 14:44
1  
@VincentWilkie people don't like scrolling horizontally ? I'm sure anyone would agree that it's 100x easier to "scroll horizontally" than it is to read code in the format it's currently in. –  Ryan Jan 30 at 14:47

1 Answer 1

Formatting your code would answer your question for you.

else if (isset($_GET['do']) && $_GET['do'] === "reg_type_2") {
    include('php-riot-api.php');
    $summoner_name_input = $_POST['summonername'];
    $summoner_name = str_replace(' ', '_', $summoner_name_input);
    $summoner_region = $_POST['summonerregion'];
    $verify_code_input = $_POST['verify_code'];
    $verify_code = str_replace(' ', '_', $verify_code_input);
    $instance = new riotapi($summoner_region);
    $grab_data = $instance->getSummonerByName($summoner_name);
    $decode_data = json_decode($grab_data);
    $grab_id = $decode_data->{'id'};
    var_dump($grab_id);
    $grab_runes = $instance->getSummoner($grab_id,'runes');
    $decode_runes = json_decode($grab_runes);
    $rune_check = $decode_runes->{'name'};

    if ($rune_check = $verify_code) {
        $logged_user = $_SESSION['logged_user'];

        if (!($stmt  = $con->prepare("INSERT INTO `verified_summoners` (`Username`,`SummonerName`,`SummonerRegion`) VALUES (?,?,?)")) || !is_object($stmt)) {
            die( "Error preparing: (" .$con->errno . ") " . $con->error);
        }

        $stmt->bind_param('sss', $logged_user, $summoner_name, $summoner_region);

        if($stmt->execute()) { 
            echo "Successfully Verified! Check out your new list! <a class='content' href='index.php'><span class='button color_yellow'>Return</span></a>";
        } else {
            echo "Unsuccessful INSERT, Contact Support or Try again...";
        }
        $stmt->close();
    } else {
        echo "O Dear, It didn't work! Try Again!";
    }
}

-

$stmt->close();
}
}

Should be

    $stmt->close();
}
share|improve this answer
    
Actually this is wrong, the extra brace is the very last one –  meda Jan 30 at 14:44
    
@meda reading through the code in my post, it looks fine to me. With the little amount of information given by OP, I think it could be the one I removed, or the very last one. It depends on where the (very well worded) "O Dear, It didn't work! Try Again!" should appear. –  Ryan Jan 30 at 14:44
    
look at his code again , the last else statment has 2 braces, yeah but you right its hard to tell because we cant see the previous lines –  meda Jan 30 at 14:45
    
Exactly. It's one of the two anyway! –  Ryan Jan 30 at 14:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.