Actually i am performing a search in my database, there are two tables, rent and sale. When user selects parameter for rent with the help of radio button and other parameters, it should search the data in rent table and return the result if it all matches. and same for second table.
But after executing my query i am getting error. Please help me in this.
I am posting all my codes here.
User selection page.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>real estate</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(document).ready(function()
{
$("input#tblsection").val('sale_table');
$('input:radio[name=rbtn]').attr('checked',true);
$("#rent").click(function() {
$("#rentselect").attr('style', 'display:block;margin-top:20px;');
$("#saleselect").attr('style', 'display:none;');
$("input#tblsection").val('rent_table');
});
$("#sale").click(function() {
$("#saleselect").attr('style', 'display:block;margin-top:20px;');
$("#rentselect").attr('style', 'display:none;');
$("input#tblsection").val('sale_table');
});
$("#srajax").click(function(){
var rentvalue = $('select#rentselect').val();
var salevalue = $('select#saleselect').val();
var location = $('select#location').val();
var area = $('select#Area').val();
var bedroom = $('select#bedroom').val();
var table = $('input#tblsection').val();
$.post(" testajax.php",
{
rentvalue: rentvalue,
salevalue: salevalue,
location: location,
area: area,
bedroom: bedroom,
table: table
},
function(data) {
alert("Data Loaded: "+data);
});
});
});
</script>
</head>
<body>
<form name="srajax" method="post">
<input type="radio" name="rbtn" value="rent" id="rent" /> <b>Rent</b>
<input type="radio" name="rbtn" value="sale" id="sale" /> <b>Sale</b>
<input type="hidden" name="tablenmae" id="tblsection" value="tablesale">
<br>
<select id="rentselect" style='display:none;'>
<option value="">----Select Budget For Rent----</option>
<option value="5000">5000</option>
<option value="5000_10000">5000 to 10000</option>
<option value="11000_20000">11000 to 20000</option>
<option value="above_20000">Above 20000</option>
</select>
<select id="saleselect" style='margin-top:20px;margin-bottom:20px;'>
<option value="">----Select Budget For Sale----</option>
<option value="5000">100000</option>
<option value="5000_10000">500000</option>
<option value="11000_20000">1000000</option>
<option value="above_20000">2500000</option>
</select>
<br>
<select id="location" name="Location">
<option>----Select Location---</option> <option value="All_Location">All Location</option>
<option value="Central_Mumbai">Central Mumbai</option>
<option value="Mumbai_Harbour">Mumbai Harbour</option>
<option value="Mumbai_Navi">Mumbai Navi</option>
<option value="Mumbai_South">Mumbai South</option>
<option value="Mumbai_Thane">Mumbai Thane</option> </select>
<br>
<br>
<select id="Area" name="Area">
<option value="">-----Select Area---</option>
<option value="All Area">All Area</option>
<option value="Bhandup">Bhandup</option>
<option value="Chembur">Chembur</option>
<option value="Kurla">Kurla</option>
<option value="Mulund">Mulund</option>
<option value="All Area">All Area</option>
<option value="Byculla">Byculla</option>
<option value="Chembur">Chembur</option>
<option value="Govandi">Govandi</option>
<option value="Sewri">Sewri</option>
<option value="Wadala">Wadala</option>
<option value="All Area">All Area</option>
<option value="Airoli">Airoli</option>
<option value="Belapur">Belapur</option>
<option value="Ghansoli">Ghansoli</option>
<option value="Mahape">Mahape</option>
<option value="Nerul">Nerula</option>
<option value="All Area">All Area</option>
<option value="Churchgate">Churchgate</option>
<option value="CST">CST</option>
<option value="Dadar">Dadar</option>
<option value="Fort">Fort</option>
<option value="All Area">All Area</option>
<option value="Brindavan">Brindavan</option>
<option value="Kalothe">Kalothe</option>
<option value="Kapur">Kapur</option>
<option value="Kalwa">Kalwa</option>
<option value="Kopat">Kopat</option> </select><br /><br>
<select id="bedroom" name="bedroom">
<option>---Select Bedroom---</option>
<option value="1BHK">1 BHK</option>
<option value="2BHK">2 BHK</option>
<option value="3BHK">3 BHK</option>
<option value="4BHK">3 BHK</option>
</select>
<br><br><br>
<input type="button" name="search" id="srajax" value="Search"/>
</form>
</body>
</html>
My search page
<?php
$host="localhost"; // Host name
$db_name="netelmbn_realestate"; // Database name
$tbl1_name="rent_table"; // Table1 name
$tbl2_name="sale_table"; //Table2 name
mysql_connect("localhost","netelmbn","password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
echo "<pre>";
print_r($_POST);
if($_POST['table'] == 'rent_table')
{
$result=mysql_query("select * from rent_table where location='$location' AND area='$area' AND bedroom='$bedroom' AND $budget='budget' ");
echo "<table cellpadding='20'>";
echo '<tr>';
while ($row = mysql_fetch_assoc($result)) {
echo "<td width='300'><strong>Budget:</strong> ".$row['budget']."<br><strong>Location</strong>: ".$row['location']."<br><strong>Area:</strong> ".$row['area']."<br><strong>BHK:</strong> ".$row['bhk']."<br></td>";
}
echo "</tr></table>";
}
if($_POST['table'] == 'sale_table')
{
$result=mysql_query("select * from sale_table where location='$location' AND area='$area' AND bedroom='$bedroom' AND $budget='budget' ");
echo "<table cellpadding='20'>";
echo '<tr>';
while ($row = mysql_fetch_assoc($result)) {
echo "<td width='300'><strong>Budget:</strong> ".$row['budget']."<br><strong>Location</strong>: ".$row['location']."<br><strong>Area:</strong> ".$row['area']."<br><strong>BHK:</strong> ".$row['bhk']."<br></td>";
}
echo "</tr></table>";
}
while ($row = mysql_fetch_assoc($result)) {
echo "<td width='300'><strong>Budget:</strong> ".$row['budget']."<br><strong>Location</strong>: ".$row['location']."<br><strong>Area:</strong> ".$row['area']."<br><strong>BHK:</strong> ".$row['bhk']."<br></td>";
}
echo "</tr></table>";
exit;
and i have rent_table
CREATE TABLE `rent_table` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`location` varchar(40) NOT NULL,
`area` varchar(40) NOT NULL,
`bedroom` varchar(20) NOT NULL,
`budget` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=58 ;
samething for sale_table
please help me where i am going wrong. Here is the error image i am getting this error:
After any and all database queries, check if the query was actually successful and use the appropriate debugging functions to find why it wasn’t. Don’t just assume that it worked.