• 06-02-2008, 23:22:43
    #1
    Merhaba,
    Yazdığım basit hesap makinesi scriptinde şöyle bir problem yaşıyorum:
    if( is_numeric($sayi1) && is_numeric($sayi2) )
    {
      if ($islem == add) {
    Yani sayi1 değişkeni ve sayi2 değişkeni numerikse, işlemleri yapan kodu çalıştırıyorum. Fakat sayfa açılmıyor. if kodu içinde if kodu çalıştırmak mümkün değil mi? case kullanmaktan başka ne yapabilirim?
    Teşekkürler...
  • 06-02-2008, 23:27:52
    #2
    Üyeliği durduruldu
    if içinde sınırsız if çalıştırabilirsin

    yanlız add i tırnak çine almayı dene

    if(is_numeric($sayi1) && is_numeric($sayi2) )
    {
    if ($islem == 'add') {
  • 06-02-2008, 23:29:38
    #3
    Üyeliği durduruldu
    if içinde sınırsız if çalıştırabilirsin
    yanlız add i tırnak çine almayı dene
    if(is_numeric($sayi1) && is_numeric($sayi2) )
    {
    if ($islem == 'add') {
  • 06-02-2008, 23:34:51
    #4
    Sorun düzelmedi, result.php dosyası:
     <html><head><title>Calculation Result</title></head>
    <body> 
    <?php
    $sayi1 = $_POST["sayi1"];
    $sayi2 = $_POST["sayi2"];
    $islem = $_POST["islem"];
    
    if( is_numeric($sayi1) && is_numeric($sayi2) ) {
    if ($islem == 'choose') {
    echo "Please choose an operation.<br />
     <b><a href='index.php'>Back</a></b>";
    }
    else if ($islem == 'sub'){
    $sonuc = $sayi1 - $sayi2;
    echo "The result is <b>".$sonuc.".</b><br /><a href='index.php'>Back</a>";
    } else if ($islem == 'add'){
    $sonuc = $sayi1 + $sayi2;
    echo "The result is <b>".$sonuc.".</b><br /><a href='index.php'>Back</a>";
    } else if ($islem == 'mul'){
    $sonuc = $sayi1 * $sayi2;
    echo "The result is <b>".$sonuc.".</b><br /><a href='index.php'>Back</a>";
    } else if($islem == 'div'){
    $sonuc = $sayi1 / $sayi2;
    echo "The result is <b>".$sonuc.".</b><br /><a href='index.php'>Back</a>";
    } else{ echo("Invalid entry - please retry"); } 
    ?>
  • 07-02-2008, 00:26:22
    #5
    bu şekilde bir deneyip sonucu buraya yazınız.

    <html><head><title>Calculation Result</title></head>
    <body> 
    <?php
    $sayi1 = $_POST["sayi1"];
    $sayi2 = $_POST["sayi2"];
    $islem = $_POST["islem"];
    if( is_numeric($sayi1) && is_numeric($sayi2) ) {
    if ($islem == 'choose') {
    echo "Please choose an operation.<br />
     <b><a href='index.php'>Back</a></b>";
    }
    else if ($islem == 'sub'){
    $sonuc = $sayi1 - $sayi2;
    echo "The result is <b>".$sonuc.".</b><br /><a href='index.php'>Back</a>";
    } else if ($islem == 'add'){
    $sonuc = $sayi1 + $sayi2;
    echo "The result is <b>".$sonuc.".</b><br /><a href='index.php'>Back</a>";
    } else if ($islem == 'mul'){
    $sonuc = $sayi1 * $sayi2;
    echo "The result is <b>".$sonuc.".</b><br /><a href='index.php'>Back</a>";
    } else if($islem == 'div'){
    $sonuc = $sayi1 / $sayi2;
    echo "The result is <b>".$sonuc.".</b><br /><a href='index.php'>Back</a>";
    } else{ echo("Invalid entry - please retry");
    }
    } 
    ?>
  • 07-02-2008, 01:08:59
    #6
    Kimlik doğrulama veya yönetimden onay bekliyor.
     <html><head><title>Calculation Result</title></head>
    <body> 
    <?php
    $sayi1 = $_POST["sayi1"];
    $sayi2 = $_POST["sayi2"];
    $islem = $_POST["islem"];
    if( is_numeric($sayi1) && is_numeric($sayi2) ) {
    if ($islem == 'choose') {
    echo "Please choose an operation.<br />
     <b><a href='index.php'>Back</a></b>";
    }
    else if ($islem == 'sub'){
    $sonuc = $sayi1 - $sayi2;
    echo "The result is <b>".$sonuc.".</b><br /><a href='index.php'>Back</a>";
    } else if ($islem == 'add'){
    $sonuc = $sayi1 + $sayi2;
    echo "The result is <b>".$sonuc.".</b><br /><a href='index.php'>Back</a>";
    } else if ($islem == 'mul'){
    $sonuc = $sayi1 * $sayi2;
    echo "The result is <b>".$sonuc.".</b><br /><a href='index.php'>Back</a>";
    } else if($islem == 'div'){
    $sonuc = $sayi1 / $sayi2;
    echo "The result is <b>".$sonuc.".</b><br /><a href='index.php'>Back</a>";
    } else{ echo("Invalid entry - please retry"); } 
    }
    ?>
    bu şekilde deneyin, değişkenlerin post ile gönderildiğine emin olun...
  • 07-02-2008, 01:29:10
    #7
    Verdiğiniz kodları uyguladım.

    Alanlara normal sayı yapıp işlemi yapınca sonuc gözüküyor, sorunsuz calısıyor. Fakat sayı yerine harf vb. yazınca Invalid entry - please retry gözükmesi gerekirken bembeyaz sayfa geliyor.

    Yardımlarınız için teşekkürler...
  • 07-02-2008, 02:15:37
    #8
    if içinde if veya döngü içinde döngü gibi işlemler yaparken her zaman kodları biraz dallandırın.hangi parantez hangi if in veya döngünün belli olsun o zaman karışıklık olmaz.parantezleri düzenledim buyrun bir deneyin...

    <html><head><title>Calculation Result</title></head>
    <body> 
    <?php
    $sayi1 = $_POST["sayi1"];
    $sayi2 = $_POST["sayi2"];
    $islem = $_POST["islem"];
    if( is_numeric($sayi1) && is_numeric($sayi2) ) {
        if ($islem == 'choose') {
            echo "Please choose an operation.<br />
            <b><a href='index.php'>Back</a></b>";
        }
        else if ($islem == 'sub'){
            $sonuc = $sayi1 - $sayi2;
            echo "The result is <b>".$sonuc.".</b><br /><a href='index.php'>Back</a>";
        }
        else if ($islem == 'add'){
            $sonuc = $sayi1 + $sayi2;
            echo "The result is <b>".$sonuc.".</b><br /><a href='index.php'>Back</a>";
        }
        else if ($islem == 'mul'){
            $sonuc = $sayi1 * $sayi2;
            echo "The result is <b>".$sonuc.".</b><br /><a href='index.php'>Back</a>";
        }
        else if($islem == 'div'){
            $sonuc = $sayi1 / $sayi2;
            echo "The result is <b>".$sonuc.".</b><br /><a href='index.php'>Back</a>";
        }
    }else{
        echo("Invalid entry - please retry");
    }
    ?>
  • 07-02-2008, 03:12:11
    #9
    Şimdi düzeldi. Fakat hatam nerdeydi anlayamadım .


    Çok teşekkürler.