Dear experts,
I've read various solutions on the error undefined index in google but i still couldnt figured out what is wrong with my code.
The original code (line 4,5, and 6) was running just fine until I included pagination code inside 🙁
Notice: Undefined index: type in C:\xampp\htdocs\cimb10\getlocationxyz.php on line 4
Notice: Undefined index: location in C:\xampp\htdocs\cimb10\getlocationxyz.php on line 5
Notice: Undefined index: price in C:\xampp\htdocs\cimb10\getlocationxyz.php on line 6
i've been pulling my hair trying to figure out what's wrong and included isset as advised in other websites , but still 😕 please please help
<?php
$gType=$_GET['type'];
$gLocation = $_GET['location'];
$gPrice = $_GET['price'];
$con = mysql_connect('localhost', 'root', '');
if (!$con) {
die('Could not connect: ' . mysql_error());
}
include 'paginationconnect.php';
$per_page = 2;
$pages_query = mysql_query("SELECT COUNT(*) FROM property");
$pages = ceil(mysql_result($pages_query,0)/$per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page-1)*$per_page;
mysql_select_db("a_database", $con);
if ($gType == "ALL" and $gLocation == "ALL" and $gPrice == "ALL") {
$sql = "SELECT Type,Price1,Location FROM property LIMIT $start,$per_page";
} else if($gType == "ALL" and $gLocation <> "ALL" and $gPrice <> "ALL") {
$sql = "SELECT Type,Price1,Location FROM property where location='" . $gLocation . "' and price='" . $gPrice ."' LIMIT $start,$per_page";
} else if($gType <> "ALL" and $gLocation == "ALL" and $gPrice <> "ALL") {
$sql = "SELECT Type,Price1,Location FROM property where type='" . $gType . "' and price='" . $gPrice ."' LIMIT $start,$per_page";
} else if($gType <> "ALL" and $gLocation <> "ALL" and $gPrice == "ALL") {
$sql = "SELECT Type,Price1,Location FROM property where type='" . $gType . "' and location='" . $gLocation ."' LIMIT $start,$per_page";
}
else if($gType <> "ALL" and $gLocation == "ALL" and $gPrice == "ALL") {
$sql = "SELECT Type,Price1,Location FROM property where type='" . $gType . "' LIMIT $start,$per_page";
}
else if($gType == "ALL" and $gLocation <> "ALL" and $gPrice == "ALL") {
$sql = "SELECT Type,Price1,Location FROM property where location='" . $gLocation . "' LIMIT $start,$per_page";
}
else if($gType == "ALL" and $gLocation == "ALL" and $gPrice <> "ALL") {
$sql = "SELECT Type,Price1,Location FROM property where price='" . $gPrice . "' LIMIT $start,$per_page";
}
else {
$sql = " SELECT Type,Price1,Location FROM property where type='" .$gType . "' and location='" . $gLocation . "' and price='" . $gPrice . "' LIMIT $start,$per_page" ;
}
$result = mysql_query($sql);
echo "<table border='1'> <tr> <th>Type</th> <th>Price</th> <th>Location</th> </tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['Type'] . "</td>";
echo "<td>" . $row['Price1'] . "</td>";
echo "<td>" . $row['Location'] . "</td>";
echo "</tr>"; }
echo "</table>";
if($pages >=1 && $page<= $pages){
for($x=1;$x<=$pages;$x++) {
echo ($x == $page) ? '<strong><a href="?page='.$x.'">'.$x.'</a> </strong>' : '<a href="?page='.$x.'">'.$x.'</a> ' ;
}}
mysql_close($con);
?>