-1

I have php code on my result page and I added some else to my php script, but i got error PHP Parse erro syntax error, unexpected else T_ELSE in / line 122

$domain_only = preg_split('/\./', $domain);

foreach($ext as $item){

    $domain = $domain_only[0].$item;

    if ( checkdnsrr($domain, 'ANY') ) {

        $response = '<tr id="com">
            <td>
                <i class="fa fa-times text-color-error"></i>
            </td>
            <td>
                <h4 class="text-color-error">'.$domain.'</h4>
            </td>
            <td class="text-color-error">Rp. 125.000</td>
            <td>
                <a class="button button-primary" href="https://www.indoip.com/whois/'.$domain.'" target="_blank" style="background: #cd3100">
                <i class="fa fa-eye icon-left"></i>Whois</a>
            </td>
        </tr>';
        }
line 122     else
        {
            //  =================================================
        $response = '<tr id="web.id">
            <td>
                <i class="fa fa-check text-color-success"></i>
            </td>
            <td>
                <h4>'.$domain.'</h4>
            </td>
            <td class="highlight">Rp. 55.000</td>
            <td>
            </td>
        </tr>';
    }
     else
        {
            //  =================================================
        $response = '<tr id="net">
            <td>
                <i class="fa fa-check text-color-success"></i>
            </td>
            <td>
                <h4>'.$domain.'</h4>
            </td>
            <td class="highlight">Rp. 93.000</td>
            <td>
            </td>
        </tr>';
    }
     else
        {
            //  =================================================
        $response = '<tr id="co.id">
            <td>
                <i class="fa fa-check text-color-success"></i>
            </td>
            <td>
                <h4>'.$domain.'</h4>
            </td>
            <td class="highlight">Rp. 80.000</td>
            <td>
            </td>
        </tr>';
    }
     else
        {
            //  =================================================
        $response = '<tr id="net.id">
            <td>
                <i class="fa fa-check text-color-success"></i>
            </td>
            <td>
                <h4>'.$domain.'</h4>
            </td>
            <td class="highlight">Rp. 65.000</td>
            <td>
            </td>
        </tr>';
    }




    echo $response;
    $i++;
}
?>

if you only use 2 else the script runs smoothly but if I add an error like the one above.

How i can resolve this error, is there code missing from my code above?

all help is greatly appreciated

Trweb
  • 3
  • 2

2 Answers2

0

You can not use multiple else my friend. You should use nested if else like:

if ( checkdnsrr($domain, 'ANY')) {
} else if ( checkdnsrr($domain, 'secondValue')) { // You are missing this part and not adding if condition
} else if (checkdnsrr($domain, 'thirdValue')) { // You are missing this part and not adding if condition
} else if (checkdnsrr($domain, 'fourthValue')) { // You are missing this part and not adding if condition
} else {
}

You can check this on link: https://www.w3schools.com/php/showphp.asp?filename=demo_if_elseif

Here you need to check your requirement and need to make your condition to show different price. I am not sure about your requirement, so I can not make particular condition for you. Hope it will help you.

Rohit Mittal
  • 2,064
  • 2
  • 8
  • 18
  • Should i add if in every else bro? like else if { ? – Trweb Feb 10 '19 at 07:24
  • @JNweb Yes, and technically you want to use [`elseif($condition)`](https://secure.php.net/manual/en/control-structures.elseif.php) rather than separated due to minor PHP lexer enhancements. – Will B. Feb 10 '19 at 07:26
  • Yes @JNweb . else statement executes when no condition matches. In your current code, you have 4 else condition where only one can execute and other 3 will never execute. It is an error. So you should add if condition in first three else condition and can keep 4th else as it is. – Rohit Mittal Feb 10 '19 at 07:31
  • SIr, sorry can you provide example with my code above? – Trweb Feb 10 '19 at 07:46
  • I have update my answer. But you need to figure out your else conditions. – Rohit Mittal Feb 10 '19 at 07:51
0

You can use one else with one if statement. If you want more else then you have to use else if

Follow it

Manzurul Hoque Rumi
  • 2,911
  • 4
  • 20
  • 43