2016-08-02 125 views
0
<form class="form-inline" id="form1" method="post" role="form" action=""> 
    <div class="from-group"> 
     <label for="usr">Search Here</label> 
     <input id="search" name="search" class="form-control" placeholder="Enter the First Name"> 
     <input type="submit" class="btn btn-success" name="SearchSubmit" value="GO" /> 
    </div> 
    <div> 
     <a class="btn btn-primary" href="logout.php">LOGOUT</a> 
    </div> 
</form> 
<?php var_dump($_POST['SearchSubmit']); ?> 
    <table class="table text-info"> 
     <tr> 
      <th class="text-center">First Name</th> 
      <th class="text-center">Last Name</th> 
      <th class="text-center">Date of Birth</th> 
      <th class="text-center">Address</th> 
      <th class="text-center">Last Passout Standard</th> 
      <th class="text-center">Last Passout Percentage</th> 
      <th class="text-center">Last Passout Year</th> 
     </tr> 
     <tbody id="log"></tbody> 
    </table> 
    <script type="text/javascript" language="javascript"> 
     <?php if($_POST['SearchSubmit']){ ?> 
      $('document').ready(function() { 
       $('#log').load('searchresult.php'); 
      }); 
      //$('#log').load('searchresult.php'); 
      <?php } ?> 
      $('document').ready(function() { 
       $('#log').load('studentList.php'); 
       }); 
      //$('#log').load('studentList.php'); 
    </script> 

上面提到的是我的代码,但我无法在我当前的php页面中加载任何日志文件。 我也打印$_POST['SearchSubmit']我得到的是空值。 我只想得到,如果搜索框被填充,所以searchresult将被加载,否则studentList将被加载。 请帮忙解决这个问题。

+0

DFK你正在使用JavaScript混合PHP的,为什么呢? – madalinivascu

+1

你的php if语句缺少php开启和关闭标记 –

+0

ohh我明白了,我是一个在PHP中的开始,所以我犯了这个错误。 –

回答

-1

一切都很好。但是您没有将操作指定给表单。将相同的页面名称设置为action.Suppose your page name is myform.php。那么action =“myform.php”。

+0

这是更多的评论,然后回答 – madalinivascu

+0

完美有效(不适用于W3C,但浏览器接受这一点) –

0

如果您使用PHP坚持下来

<?php if(isset($_POST['SearchSubmit'])){ 
include 'searchresult.php'; 
} else { 
include 'studentList.php'; 
}?>