I'm declaring this two but I always get error. I'm thinking of isset but I don't know how to use it. It's been my 3 weeks self-studying PHP and i'm not really good yet.
$searchq = $_POST['lname'];
$searchw = $_POST['fname'];
This are my errors:
Undefined variable: searchq
Undefined variable: searchw
I will appreciate any help.
$per_page = 20;
$pages_query = mysql_query("SELECT COUNT(fname) FROM sheet1");
$pages = ceil(mysql_result($pages_query, 0) / $per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
if( (isset($_POST['fname'])) && (isset($_POST['lname'])) ){
($searchq = $_POST['lname']);
($searchw = $_POST['fname']);
}
$query = mysql_query("SELECT * FROM sheet1 WHERE lname like '%$searchq%' AND fname like '%$searchw%' LIMIT $start, $per_page");
while($query_row = mysql_fetch_assoc($query)){
echo '<p>', $query_row['fname'] . ' ' . $query_row['lname'] ,'</p>';
}
if($pages >= 1 && $pages <= $pages){
for($x=1; $x<=$pages; $x++){
echo ($x == $page) ? '<strong><a href="?page='.$x.'">'.$x.'</a></strong> ' : '<a href="?page='.$x.'">'.$x.'</a> ';
}
}
This the whole content of my code. I'm making a search box but every time I enter in empty value I got the error and it displays all the records in my database.