samedi 10 novembre 2018

PHP else statement inside if statement

I am trying to make a simple php application which spits out strings.

test.php:

<?php
if ($_GET) {
    $par1 = $_GET['par1'];
    $par2 = $_GET['par2'];
} else {
    $par1 = $argv[1];
    $par2 = $argv[2];
}
if ( $par1 == 'Apple' ) {
    if ( $par2 == 'Banana' ) {
        echo 'Juice';
    else {
        echo 'Wrong Statement';
    }
}
elseif ( $par1 == 'Blueberry' ) {
    if ( $par2 = 'Strawberry' ) {
        echo 'Berry Blast';
    }
    elseif ( $par2 == 'Banana' ) {
        echo 'Double B';
    }
    else {
        echo 'Wrong Statement';
    }
}
else {
    echo 'Not a Juice';
}
?>

However, when i request example.com/test.php?v=web&get=Latest , it spits out:

syntax error, unexpected 'else' (T_ELSE) on line 13

And, when I remove all the else statements, it returns with:

syntax error, unexpected end of file on line 20

What should I do? (btw, I'm totally new php. I wanted to implement auto update feature to my python app and this happened.)

Aucun commentaire:

Enregistrer un commentaire