doumixiang2227
2014-10-01 05:31
浏览 18

解析错误语法错误PHP [关闭]

Somebody help me please, i am a beginner of php programming,

i get message like this:

Parse error: syntax error, unexpected '(', expecting variable (T_VARIABLE) or '$' in C:\Users\Sendi\Documents--- Khoreiza\xampp\htdocs\ABRN\content\users\form.php on line 2

and this is the error code:

$(function(){
$("#province_wrapper").hide();
$("#kelas").change(function(){
    if($(this).val() != 0){
        $("#province_wrapper").show();
        $.get("ajax.php?id_kelas="+$(this).val(),function(anggota){
            var p_html = "";
            for(var i=0;i<anggota.length;i++){
                p_html += "<option value='"+anggota[i].noanggota+"'>"+anggota[i].nama_lengkap+"</option>";
            }
            $("#anggota").html(p_html);
        },"json");
      }
      });
  });
?>
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanbu9345 2014-10-01 05:35
    已采纳

    Since that code is not PHP, it should not be inside the <?php ... ?> block. Remove those tags around it, so it will just be output literally.

    If this Javscript code is in an HTML page, it should be inside a <script> tag, so it should be:

    <script>
    $(function(){
        $("#province_wrapper").hide();
        $("#kelas").change(function(){
            if($(this).val() != 0){
                $("#province_wrapper").show();
                $.get("ajax.php?id_kelas="+$(this).val(),function(anggota){
                    var p_html = "";
                    for(var i=0;i<anggota.length;i++){
                        p_html += "<option value='"+anggota[i].noanggota+"'>"+anggota[i].nama_lengkap+"</option>";
                    }
                    $("#anggota").html(p_html);
                },"json");
            }
        });
    });
    </script>
    
    打赏 评论
  • douliao8318 2014-10-01 05:41

    You wrote jQuery code in <?php ?> block, you should not do that.

    Close the <?php ?> tags, then write the jQuery code:

    Here is an example:

    <?php //your old code
    
    //close php tag
    ?>
    
    //then start jquery code
    
    $(function(){
    $("#province_wrapper").hide();
    $("#kelas").change(function(){
        if($(this).val() != 0){
            $("#province_wrapper").show();
            $.get("ajax.php?id_kelas="+$(this).val(),function(anggota){
                var p_html = "";
                for(var i=0;i<anggota.length;i++){
                    p_html += "<option value='"+anggota[i].noanggota+"'>"+anggota[i].nama_lengkap+"</option>";
                }
                $("#anggota").html(p_html);
            },"json");
          }
          });
      });
    <?php ?>
    
    打赏 评论

相关推荐 更多相似问题