Nerede bu kodda probem (javascript) nedir?

5 Cevap php

Benim kodunda bir sorun var.

Herkes bana yardımcı olabilir ...

<html>
    <body>
    <script type="text/javascript">
        <?php
        $conn = mysql_connect("localhost","root");
        mysql_select_db("tr", $conn); 
        $q = mysql_query("SELECT message FROM messages WHERE to_viewed = '0' ");

        if (mysql_num_rows($q)) {
            require('pm.php');
            ?>
            var answer = confirm("you have new message ");
            <?php
        }
        ?>
        if (answer) {
            window.location = "http:>>>/";
        } else {
        }

    //-->
    </script>
</body>
</html>

Teşekkürler ....

Benim kod görünen hata onaylama I (çıkış yok) benim sayfasını açarsanız çalışmıyor olmasıdır

5 Cevap

Satırlar "cevap", iade varsa sadece onaylamak gösteren konum göz önüne alındığında hem de doğrusu bunun dışında daha bu alanda olmalıdır.

Emin satır iade ediliyor musunuz? Hızlı bir yankı yapmak ... echo @mysql_num_rows($q); () emin bir şey olması bile iade ediliyor ise önce.

<html>
    <body>
    <script type="text/javascript">
        <?php
        $conn = mysql_connect("localhost","root");
        mysql_select_db("tr", $conn); 
        $s = "SELECT message FROM messages WHERE to_viewed = '0' ");
        //you can remove the trigger_error() call on the live server
        //and place an @ before mysql_query to stifle errors from being displayed
        $q = mysql_query($s) or trigger_error(mysql_error());

        //you can take this comment and the next line out, just testing for result
        echo '<p>Rows: '.mysql_num_rows($q).'</p>';

        if(mysql_num_rows($q) > 0) {
            require('pm.php');
            ?>
            var answer = confirm("you have new message");
            if(answer) {
                window.location = "http://domain.com/page"
            } else {
                //whatever action if no action, you don't need the else
            }
        }
    </script>
</body>
</html>

Bir kere, window.location = "http:>>>/"; Bu ileti görünmeye neden olur: This URL does not have any code saved to it

Eğer yapıyorduk sorun hakkında bir şey söylemek ama to_viewed eğer bir tamsayı alanı olan, sorgudan dışarı tırnak almak youll gerek yoktu

SELECT message FROM messages WHERE to_viewed = 0

Eğer answer tanımlı değil ilgili hatalar istemci tarafında alıyorsanız yeni mesajlar (var answer = false;) veya ondan tamamen kurtulmak (beri varken, değer false atamak gerekir ya o) gerekli değildir.

<html>

    <body>


        <script type="text/javascript">


<?php

$conn = mysql_connect("localhost","root");
mysql_select_db("tr", $conn); 
$q = mysql_query("SELECT message FROM messages WHERE to_viewed = '0' ");

    if (mysql_num_rows($q))
{
  require('pm.php');

    ?>

    if (confirm("you have new message ")){

        window.location = "http://mywebsite.com/";
    }
    else{

    }

<?php

}
    ?>

//-->
</script>



</body>
</html>

Bu bozkır aslında hataları alıyorsanız çıkan komut dosyasını görüntülemek için yararlı olabilir. Tarayıcınızda bir 'Kaynağı Görüntüle' yapın ve çıkan müşteri kodunuzu kontrol edin.