if-else在javascript中无法正常工作

I'm trying to display the value returned by the php when a ajax call made to it with specified parameter.

This is my php code:

<?php
    $service_id = mt_rand( 10000000, 99999999 );
    $query = "insert into `service` (`id`,`time`,`date`,`city`,`service_type`,`locality`,`name`,`area`,`phone`,`address`)    values('$service_id','$time','$date','$city','$service','$locality','$name','$area','$phone','$address')";
    $result = $sql->query( $query );
    if ( $result ) 
        $x = $service_id;
    else
        $x = 0;

    echo $x;
?>

This is my ajax function:

var xml = ajax();
if (xml) {
    xml.open("POST", url);
    xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xml.onreadystatechange = function () {
        if (xml.readyState == 4 && xml.status == 200) {
            var reply = xml.responseText;
            var x = reply.length;
            if (x == 8){
                document.getElementById('login-form').style.visibilty='visible';
                document.getElementById('seconday-form').style.visibility='hidden';
            }
            else
               document.getElementById('message').innerHTML=reply;
        }
    }
    xml.send(data);

Everything works fine except the last if-else block. if condition never gets executed even the returned value from php is of length 8.

Update I have included the code which will be executed on each condition true