Reputation: 299
this is going to drive me mad, because its probably something I have missed but I have a form that the user selects a country and a league name, and returns a table of the found results.
The problem I am having is that if that search form is submitted it returns nothing, but if I just refresh the page as normal with no submit it works fine and returns all the results. As you can see below it sets the $subleaguesearch and $countrysearch variables if the form has not been submitted and thats working fine, its just when it has been submitted that is not, and I just can't seem to find why. Any help would be great! thanks.
p.s I am receiving no error message its just not returning anything at all. And I have echoed the variables back to screen after the form submittion and they echoed back with the correct values so I know the variables are being set ok!.
<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 </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 </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/> Error - could not display league");
Upvotes: 1
Views: 97
Reputation: 19251
Imagining you problem is in this code:
$subleaguesearch = mysql_real_escape_string($_POST['country']);
$countrysearch = mysql_real_escape_string($_POST['subleaguesearch']);
if($countrysearch == 0){
$countrysearch = "%%";
}
First, you should check and make sure that $_POST['country'] and $_POST['subleaguesearch'] contain what you think they contain. If they do not, then you named the field in your form wrong most likely.
Second, it seems that you have assigned the wrong post fields to the wrong search variables. Notice $subleaguessearch = $_POST['country'] instead of equaling $_POST['subleaguesearch']. same with $countrysearch. So instead it should be something like:
$subleaguesearch = mysql_real_escape_string($_POST['subleaguesearch ']);
$countrysearch = mysql_real_escape_string($_POST['country']);
Upvotes: 1