2012-02-10 32 views
1

这是要我发疯,因为它可能不是我错过了,但我有一个用户选择了一个国家,一个联盟名称,并返回找到的结果表形式返回数据。PHP不是从形式

我遇到的问题是,如果该搜索表单提交它没有返回值,但如果我只是刷新页面正常,没有提交它工作正常,并返回所有结果。正如你可以看到它下面设置$ subleaguesearch和$ countrysearch变量如果表单没有被提交,这就是做工精细,它只是当它已经提交,是不是,我只是似乎无法找到原因。任何帮助将是伟大的!谢谢。

P.S我没有收到错误消息,它只是不返回任何东西。我在表单提交后将变量回显到屏幕上,并用正确的值回显,所以我知道变量已设置好!

 <form action="" method="post" autocomplete="off"> 
     <table id="searchsubleaguetable" width="670px" align="left" cellpadding="1" cellspacing="0">  
        <tr colspan="2"> 
        <th colspan="2" align="left"><label>SEARCH SUBLEAGUES</th> 
        </tr> 
        <tr> 
        <td align="right"><label>COUNTRY&nbsp;&nbsp;</td> 
        <td align="left"><SELECT NAME="country" style="font-size:12px; padding:4px;"><OPTION VALUE="0">All Countries<?php echo $options;?></option></SELECT></label></td> 
        </tr> 
        <tr> 
        <td align="right"><label>SEARCH&nbsp;&nbsp;</td> 
        <td align="left"><input class="searchinputs" type="text" name="subleaguesearch" size="40" value=""></label></td> 
        </tr> 
        <tr width="100%" height="20px" colspan="2"> 
        <td align="right"><label></td> 
        <td align="left"><input class="searchbutton" type="submit" value="Search" name="searchsubnow"></label></td> 
        </tr> 
       </table> 
      </form> 




     if (isset($_POST['searchsubnow'])){ 
      $subleaguesearch = mysql_real_escape_string($_POST['country']); 
      $countrysearch = mysql_real_escape_string($_POST['subleaguesearch']);   
      if($countrysearch == 0){ 
      $countrysearch = "%%"; 
      } 
     }else{ 
      $subleaguesearch = ""; 
      $countrysearch = "%%"; 
     } 

     $rowsPerPage = 15; 
     $pageNum = 1; 

     if(isset($_GET['page'])){ 
      $chosenpage = mysql_real_escape_string($_GET['page']); 
      $pageNum = $chosenpage; 
     } 

     $offset = ($pageNum - 1) * $rowsPerPage; 

     $result = mysql_query(" SELECT s.league_id, s.leaguename, s.private, s.date, u.flag, u.firstname, u.country, 
           COALESCE(SUM(r.total_points),0) as totalpoints, 
           count(m.member_id) participants 
           from sub_leagues s 
           Left Join members_leagues m 
           On m.league_id = s.league_id 
           Left Join member_results r 
           On r.member_id = m.member_id 
           join members u 
           on s.admin = u.member_id 
           WHERE u.country LIKE '$countrysearch' 
           AND s.leaguename LIKE '$subleaguesearch%' 
           Group By s.league_id 
           Order By r.total_points DESC, participants DESC, s.date ASC " . " LIMIT $offset, $rowsPerPage") 
         or die ("<br/>&nbsp;Error - could not display league"); 
+0

我们能看到表格吗?当你说刷新时,你的意思是提交之前的请求中的表单后刷新? – dqhendricks 2012-02-10 19:33:38

+1

您可以添加HTML表单,以便我们可以看到它们如何组合在一起? – Chillie 2012-02-10 19:34:29

+0

当我说我刷新的意思只是加载页面正常,没有submittion的形式。 – user969729 2012-02-10 19:34:35

回答

1

想象你的问题是在此代码:

$subleaguesearch = mysql_real_escape_string($_POST['country']); 
$countrysearch = mysql_real_escape_string($_POST['subleaguesearch']);   
if($countrysearch == 0){ 
    $countrysearch = "%%"; 
} 

首先,你应该检查,确保$ _ POST [“国家”]和$ _ POST [“subleaguesearch”]包含你在想什么他们包含。如果他们不这样做,那么你最有可能错误地将该字段命名为错误。

其次,它似乎你已经分配了错误的后场到错误的搜索变量。注意$ subleaguessearch = $ _POST ['country']而不是等于$ _POST ['subleaguesearch']。同$ countrysearch一样。所以相反,它应该是这样的:

$subleaguesearch = mysql_real_escape_string($_POST['subleaguesearch ']); 
$countrysearch = mysql_real_escape_string($_POST['country']); 
+0

啊,我的上帝,哈哈有时候,你只需要新鲜一双眼睛,看看它为你!非常感谢!多么浪费大家的时间......对不起。 – user969729 2012-02-10 19:43:50

+0

@ user969729不用担心。很高兴我能帮上忙。 – dqhendricks 2012-02-10 19:49:01