Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem z deklaracją funkcji
Forum PHP.pl > Forum > Po stronie przeglądarki
robal94
Witam! Mam napisaną stronę z formularzem ze skryptem który po wciśnięciu przycisku sprawdź sprawdza czy dany urzytkownik istnieje. Oto cały kod strony:
  1. $ilpoczta=0;
  2. $login=$_SESSION['login'];
  3. $zamiana = array('ą', 'Ą', 'ć', 'Ć', 'ł', 'Ł', 'ó', 'Ó', 'ś', 'Ś', 'ę', 'Ę', 'ń', 'Ń', 'ż', 'Ż', 'ź', 'Ź', 'ˆ' );
  4. $cenzura = array('^a^', '^A^', '^c^', '^C^', '^l^', '^L^', '^o^',' ^O^', '^s^', '^S^', '^e^', '^E^', '^n^', '^N^','^z^', '^Z^','^x^','^X^', '^*c*^');
  5. $tytul =str_replace( $cenzura, $zamiana, $tytul );
  6. $klucze =str_replace( $cenzura, $zamiana, $klucze );
  7. $opis =str_replace( $cenzura, $zamiana, $opis );
  8. $name='index';
  9. mysql_connect('localhost', 'epamiec_robal94', 'logika94');
  10. mysql_select_db('epamiec_epamiec');
  11. $zapytanie=mysql_query("select * FROM klucze WHERE name='$name'");
  12. while($row = mysql_fetch_array($zapytanie)){
  13. $opis= str_replace( $cenzura, $zamiana, $row['opis']);
  14. $klucze= str_replace( $cenzura, $zamiana, $row['klucze']);
  15. $tytul = str_replace( $cenzura, $zamiana, $row['tytul']);
  16. $tresc = str_replace( $cenzura, $zamiana, $row['tresc']);
  17. }
  18. $cz1 = fread(fopen("index1.php", "r"), filesize("index1.php"));
  19. $cz2 = fread(fopen("index2.php", "r"), filesize("index2.php"));
  20. $cz3 = fread(fopen("index3.php", "r"), filesize("index3.php"));
  21. $log1 = fread(fopen("log1.php", "r"), filesize("log1.php"));
  22. $log2 = fread(fopen("log2.php", "r"), filesize("log2.php"));
  23. $poczta=mysql_query("select status From poczta Where adresat='$login'");
  24. while($row = mysql_fetch_array($poczta)){
  25.  
  26. if($row['status'] == 1){
  27. $ilpoczta++;
  28. }
  29.  
  30. }
  31.  
  32.  
  33. ?>
  34. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//PL">
  35. <HTML>
  36. <HEAD>
  37. <title><?echo $tytul;?></title>
  38. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  39. <meta name="Description" content="<?echo $opis?>" />
  40. <meta name="Keywords" content="<?echo $klucze;?>" />
  41. <meta http-equiv="Content-Language" content="pl" />
  42. <meta name="Author" content="Tobiasz Boral" />
  43. <meta name="Robots" content="all" />
  44. <link rel="stylesheet" href="style.css" type="text/css" />
  45. <link rel="shortcut icon" href="gif/epamiec.ico" type="image/x-icon" />
  46. <script type="text/javascript" src="moduly.js"></SCRIPT>
  47. <script type="text/javascript">
  48. function funkcja(){
  49. var formlularz = document.forms['nowawiad'].elements['adresat'].value;
  50. var ajaxRequest;
  51.  
  52. try{
  53.  
  54. ajaxRequest = new XMLHttpRequest();
  55. } catch (e){
  56.  
  57. try{
  58. ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
  59. } catch (e) {
  60. try{
  61. ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
  62. } catch (e){
  63.  
  64. alert("Twoja ptzeglądarka nie obsługuje AJAX'a!");
  65. return false;
  66. }
  67. }
  68. }
  69.  
  70. ajaxRequest.onreadystatechange = function(){
  71. if(ajaxRequest.readyState == 4){
  72. var zmienna = ajaxRequest.responseText;
  73. if(zmienna == 0){
  74. var el;
  75. el = document.getElementById('zle');
  76. el.innerHTML = 'Uzytkownik nie istnieje!';
  77.  
  78.  
  79. }
  80. else{
  81. var el;
  82. el = document.getElementById('button');
  83. el.innerHTML = '<button type="sumbit">Wyślij</button>';
  84.  
  85. }
  86.  
  87. }
  88. ajaxRequest.open("GET", 'mysql_adresat.php?adresat='+formularz+'', true);
  89. ajaxRequest.send(null);
  90.  
  91. }
  92. </SCRIPT>
  93.  
  94. </HEAD>
  95. <BODY onLoad="onload();" >
  96. <?echo $cz1;?>
  97. <div id="logowanie">
  98. <?php
  99. if($_SESSION['status'] == 0){
  100. echo $log1;
  101. }
  102. elseif($_SESSION['status'] > 0){
  103. echo "<b css='log'>Witaj ",$login,"!</b><br><a href='skrzynka.php' css='wiad'>Wiadomości(",$ilpoczta,")</a><br>",$log2;
  104.  
  105. }
  106. ?>
  107. </div>
  108. <?echo $cz2;?>
  109. <div id="srodek">
  110. <div id="text">
  111. <form id="nowawiad" css="nowawiad" method="post" action="skrzynka.php?wyslij=1">
  112. Adresat:<input type="text" name="adresat" value="<?echo $_GET['adresat']?>"/><div id="zle"></div><br>
  113. Tytuł :<input type="text" name="tytul" size="40" /><br>
  114. <textarea name="tresc" cols="50" rows="20"> </textarea><br>
  115. <div id="button"><button type="button" onClick="funkcja();">Sprawdź</button></div>
  116. </form>
  117.  
  118.  
  119. </div>
  120. </div>
  121. <?echo $cz3;
  122.  
  123. </BODY>
  124. </HTML>


Jednak nie działa! Konsola google chrome mówi mi że funckja "funkca" jest niezdeklarowana! O co chodzi?

Edit: Dodatkowo wyświetla jeszcze: Uncaught SyntaxError: Unexpected end of input
melkorm
Kod
    <script type="text/javascript">
    function funkcja(){
    var formlularz = document.forms['nowawiad'].elements['adresat'].value;
    var ajaxRequest;

    try{

        ajaxRequest = new XMLHttpRequest();
    } catch (e){

        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){

                alert("Twoja ptzeglądarka nie obsługuje AJAX'a!");
                return false;
            }
        }
    }

    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){
            var zmienna = ajaxRequest.responseText;
            if(zmienna == 0){
                var el;
                el = document.getElementById('zle');
                el.innerHTML = 'Uzytkownik nie istnieje!';


            }
            else{
                var el;
                el = document.getElementById('button');
                el.innerHTML = '<button type="sumbit">Wyślij</button>';

            }

    }
    ajaxRequest.open("GET", 'mysql_adresat.php?adresat='+formularz+'', true);
    ajaxRequest.send(null);

}
    </SCRIPT>

masz źle domknięcia, a żeby nei było tak łatwo to poszukasz sam.
robal94
Domknięcie znalazłem, ale nadal pisze że funkcja niezdeklarowana. W czym tkwi problem?
melkorm
A pokażesz kod ? Czy mam strzelać?
robal94
pokazuje mi Uncaught ReferenceError: formularz is not defined. A kod to ten co na początku dałem i w momencie naciśnięcia przycisku nic się nie dzieje
melkorm
Bo masz literówkę? :|
robal94
ale gdzie? Przecież nie ma literówki?
Oto ten kod z poprawnymi klamrami:
  1. <?session_start();
  2. ob_start();
  3. $ilpoczta=0;
  4. $login=$_SESSION['login'];
  5. $zamiana = array('ą', 'Ą', 'ć', 'Ć', 'ł', 'Ł', 'ó', 'Ó', 'ś', 'Ś', 'ę', 'Ę', 'ń', 'Ń', 'ż', 'Ż', 'ź', 'Ź', 'ˆ' );
  6. $cenzura = array('^a^', '^A^', '^c^', '^C^', '^l^', '^L^', '^o^',' ^O^', '^s^', '^S^', '^e^', '^E^', '^n^', '^N^','^z^', '^Z^','^x^','^X^', '^*c*^');
  7. $tytul =str_replace( $cenzura, $zamiana, $tytul );
  8. $klucze =str_replace( $cenzura, $zamiana, $klucze );
  9. $opis =str_replace( $cenzura, $zamiana, $opis );
  10. $name='index';
  11. mysql_connect('localhost', 'epamiec_robal94', 'logika94');
  12. mysql_select_db('epamiec_epamiec');
  13. $zapytanie=mysql_query("select * FROM klucze WHERE name='$name'");
  14. while($row = mysql_fetch_array($zapytanie)){
  15. $opis= str_replace( $cenzura, $zamiana, $row['opis']);
  16. $klucze= str_replace( $cenzura, $zamiana, $row['klucze']);
  17. $tytul = str_replace( $cenzura, $zamiana, $row['tytul']);
  18. $tresc = str_replace( $cenzura, $zamiana, $row['tresc']);
  19. }
  20. $cz1 = fread(fopen("index1.php", "r"), filesize("index1.php"));
  21. $cz2 = fread(fopen("index2.php", "r"), filesize("index2.php"));
  22. $cz3 = fread(fopen("index3.php", "r"), filesize("index3.php"));
  23. $log1 = fread(fopen("log1.php", "r"), filesize("log1.php"));
  24. $log2 = fread(fopen("log2.php", "r"), filesize("log2.php"));
  25. $poczta=mysql_query("select status From poczta Where adresat='$login'");
  26. while($row = mysql_fetch_array($poczta)){
  27.  
  28. if($row['status'] == 1){
  29. $ilpoczta++;
  30. }
  31.  
  32. }
  33.  
  34.  
  35. ?>
  36. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//PL">
  37. <HEAD>
  38. <title><?echo $tytul;?></title>
  39. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  40. <meta name="Description" content="<?echo $opis?>" />
  41. <meta name="Keywords" content="<?echo $klucze;?>" />
  42. <meta http-equiv="Content-Language" content="pl" />
  43. <meta name="Author" content="Tobiasz Boral" />
  44. <meta name="Robots" content="all" />
  45. <link rel="stylesheet" href="style.css" type="text/css" />
  46. <link rel="shortcut icon" href="gif/epamiec.ico" type="image/x-icon" />
  47. <script type="text/javascript" src="moduly.js"></SCRIPT>
  48. <script type="text/javascript">
  49. function funkcja(){
  50. var formlularz = document.forms['nowawiad'].elements['adresat'].value;
  51. var ajaxRequest;
  52.  
  53. try{
  54.  
  55. ajaxRequest = new XMLHttpRequest();
  56. } catch (e){
  57.  
  58. try{
  59. ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
  60. } catch (e) {
  61. try{
  62. ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
  63. } catch (e){
  64.  
  65. alert("Twoja ptzeglądarka nie obsługuje AJAX'a!");
  66. return false;
  67. }
  68. }
  69. }
  70.  
  71. ajaxRequest.onreadystatechange = function(){
  72. if(ajaxRequest.readyState == 4){
  73. var zmienna = ajaxRequest.responseText;
  74. if(zmienna == 0){
  75. var el;
  76. el = document.getElementById('zle');
  77. el.innerHTML = 'Uzytkownik nie istnieje!';
  78.  
  79.  
  80. }
  81. else{
  82. var el;
  83. el = document.getElementById('button');
  84. el.innerHTML = '<button type="sumbit">Wyślij</button>';
  85.  
  86. }
  87.  
  88. }
  89. }
  90. ajaxRequest.open("GET", 'mysql_adresat.php?adresat='+formularz+'', true);
  91. ajaxRequest.send(null);
  92.  
  93. }
  94. </SCRIPT>
  95.  
  96. </HEAD>
  97. <BODY onLoad="onload();" >
  98. <?echo $cz1;?>
  99. <div id="logowanie">
  100. <?php
  101. if($_SESSION['status'] == 0){
  102. echo $log1;
  103. }
  104. elseif($_SESSION['status'] > 0){
  105. echo "<b css='log'>Witaj ",$login,"!</b><br><a href='skrzynka.php' css='wiad'>Wiadomości(",$ilpoczta,")</a><br>",$log2;
  106.  
  107. }
  108. ?>
  109. </div>
  110. <?echo $cz2;?>
  111. <div id="srodek">
  112. <div id="text">
  113. <form id="nowawiad" css="nowawiad" method="post" action="skrzynka.php?wyslij=1">
  114. Adresat:<input type="text" name="adresat" value="<?echo $_GET['adresat']?>"/><div id="zle"></div><br>
  115. Tytuł :<input type="text" name="tytul" size="40" /><br>
  116. <textarea name="tresc" cols="50" rows="20"> </textarea><br>
  117. <div id="button"><button type="button" onClick="funkcja();">Sprawdź</button></div>
  118. </form>
  119.  
  120.  
  121. </div>
  122. </div>
  123. <?echo $cz3;
  124. ob_end_flush();?>
  125.  
  126. </BODY>
  127. </HTML>
melkorm
Kod
var formlularz = document.forms['nowawiad'].elements['adresat'].value;


wcale ... .
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.