Hi again , i had hoped to never need your help again but i discovered a big enough bug in one of my search sections
I have a two basic searches in my website which displays a set of results depending on whats asked . One of them searches is a basic name search so ill post that one here in the hopes i can learn what to do with second one.
I have a page search_Name.php which originally posted a value to search_Name1.php The only problem was this would only pass the value one and after that is would have no search parameter and using LIKE %$name% would then return the entire user list.
I then changed search_Name.php to post to itself and then take the variable and link the URL with the variable embedded.
This worked to a certain degree but once i click on the second page it again acts as if the ?name= was never put into the URL
Heres the code hopefully i explained the problems well enough.
<?php
require_once('auth.php');
require_once('config.php');
require_once('opendb.php');
require_once('complete1.php');
session_start();
$user = $_SESSION['SESS_USERNAME'];
$id= $_SESSION['SESS_MEMBER_ID'];
function clean($str) {
$str = trim($str);
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
$name = clean($_REQUEST['name']);
if ($name=="")
{
$errmsg_arr[] = 'Try entering a name';
$errflag = true;
}
// find out how many rows are in the table
$sql = "SELECT COUNT(*) as number FROM members
WHERE login LIKE '%$name%'
AND members.member_id <> $id
AND members.allowed = 1
AND members.complete = 1";
//$sql = "SELECT COUNT(*) FROM members";
$result = mysql_query($sql) or die (mysql_error());
$r = mysql_fetch_row($result);
$numrows = $r[0];
$number = $r['number'];
if($numrows==0)
{
$errmsg_arr[] = 'no results found';
$errflag = true;
}
//If there are input validations, redirect back to the registration form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
header("location: search_Name.php");
exit();
}
?><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" media="screen" title="style (screen)" />
<title></title>
</head>
<body>
<table width=100% height="100" border="0" cols="10">
<tr>
<td height="100" colspan="11"><h1>
eHarmonize
</h1>
<h2>'Cause you hate being a loner !' </h2></td>
<td width="18%" colspan=""><img href="in.php" name="Window" src="images/hands.jpg" width="292" height="162">
<td></td></td>
</tr>
</table>
<br/>
<br/>
<table width="100%" border="0">
<td > <div align="center"> <a href="home_Profile.php"title="View and change your profile!"><b><span>My Profile</span></b></a></div></td >
<td > <div align="center"><a href="inbox.php" title="Read mail and message others!"><b><span>Mail</span></b></a></div> </td >
<td > <div align="center"> <a href="search.php" title="Search for other users!"><b><span>Search for love</span></b></a></div></td >
<td > <div align="center"><a href="favourites.php" title="View your favourties!"><b><span>Favourites</span></b></a></div></td >
<td > <div align="center"> <a href="logout.php" title="Log off the website!"><b><span>Logout</span></b></a></div></td >
</table>
<div id="container">
<br/><br/><br/><br/>
<div id="left-column">
<div id="menu11">
<ul>
<li><a href="search_Compatibility.php">Search By Compatibility </a></li>
<li><a href="search_Area.php">Search By Basic Details</a></li>
<li><a href="search_Name.php">Search By Name</a></li>
</ul>
</div>
</div>
<?php
// number of rows to show per page
$rowsperpage = 5;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
?>
<?php
// get the info from the db
$sql = "SELECT members.dob, members.login, members.member_id, member_details.interests
FROM members
INNER JOIN member_details ON members.member_id = member_details.user_id
INNER JOIN rtchoice ON members.member_id = rtchoice.rtchoice_id
INNER JOIN alchoice ON members.member_id = alchoice.alchoice_id
WHERE login LIKE '%$name%'
AND members.member_id <> $id
AND members.allowed = 1
AND members.complete = 1
LIMIT $offset, $rowsperpage";
$result = mysql_query($sql) or die (mysql_error());
// while there are rows to be fetched...
while ($list = mysql_fetch_assoc($result))
{
$dob = $list['dob'];
$member_login = $list['login'];
$member_id = $list['member_id'];
$interests = $list['interests'];
$age = floor((time() - strtotime($dob))/(60*60*24*365.2425));
?>
<div id="content">
<table columns ="3" border="1" witdth ="100%">
<td width="12%"><img src= "show.php?member_id=<?php echo $member_id; ?>" height="94" width="94"></td>
<td width="20%">
<a>Name:</a><a href = "user_Profile.php?user_id=<?php echo $member_login; ?>"><name><?php echo $member_login; ?></name><br/>
<a>Age:</a> <b><?php echo $age?></b><br />
</td>
<td width="50%">
<b> Interests: <b><br/>
<z><?php echo $interests ?></z>
</td>
</div>
</table>
<?php
} // end while
/****** build the pagination links ******/
// range of num links to show
$range = 3;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?name=$name?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?name=$name?currentpage=$prevpage'><</a> ";
} // end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
} else {
// make it a link
echo " <a href='{$_SERVER['PHP_SELF']}?name=$name?currentpage=$x'>$x</a> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?name=$name?currentpage=$nextpage'>></a> ";
// echo forward link for lastpage
echo " <a href='{$_SERVER['PHP_SELF']}?name=$name?currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/
?>
</div>