hybmg57 Posted July 3, 2010 Share Posted July 3, 2010 Hi I have a search form that I created and trying to parse info entered from advanced search form to the search results page and I get this error... You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND BEDS >=0 AND BATHSTOTAL >=0 AND LISTPRICE >=0 AND LI' at line 5 Here is the code for the search results page... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>JR Molina</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="robots" content="index,follow" /> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /> <link rel="apple-touch-icon" href="/apple-touch-icon.png"/> <link charset="utf-8" type="text/css" rel="stylesheet" media="all" href="results.css" /> <?php if (is_numeric($_GET['pg'])) { $pgnum = ((int) $_GET['pg']); } else { $pgnum = 0; $errorMessage = "Invalid value for page number"; } $startnum = 1; $nextpg = ($pgnum + 1); $prevpg = ($pgnum-1); if ($pgnum >= 0) { $offset = ($pgnum * 20); } else { $offset = 0; } $limit = 20; ?> <?php $Property_Type=$_GET['property_type']; $City=$_GET['city']; $Beds=$_GET['beds']; $Baths=$_GET['baths']; $Lowest_Price=$_GET['lowest_price']; $Highest_Price=$_GET['highest_price']; $MLS=$_GET['mls_number']; $AddressA=$_GET['address']; $Zip_codeA=$_GET['zip_code']; $SubdivisionA=$_GET['subdivision']; $GarageA=$_GET['garage']; $StoriesA=$_GET['stories']; $FireplacesA=$_GET['fireplaces']; $Yard_sizeA=$_GET['yard_size']; $CitiesA=$_GET['cities']; $AreasA=$_GET['areas']; $CountiesA=$_GET['counties']; $School_districtA=$_GET['school_district']; $School_elementaryA=$_GET['school_type[elementary]']; $School_middleA=$_GET['school_type[middle]']; $School_highA=$_GET['school_type[high]']; $School_nameA=$_GET['school_name']; $Guest_quartersA=$_GET['property[guest-quarters]']; $High_riseA=$_GET['property[high-rise-condominium]']; $Loft_A=$_GET['property[loft]']; $BalconyA=$_GET['property[balcony]']; $LibraryA=$_GET['property[library-or-study]']; $MediaA=$_GET['property[media-room]']; $Gated_communityA=$_GET['location[gated-community]']; $Golf_course_communityA=$_GET['location[golf-course-community]']; $Golf_course_lotA=$_GET['location[golf-course-lot]']; $Lake_front_lotA=$_GET['location[lake-front-lot]']; $Lake_viewA=$_GET['location[lake-view]']; $Handicap_amenitiesA=$_GET['location[handicap-ammenities]']; $Zero_lot_lineA=$_GET['location[zero-lot-line]']; $Horses_allowedA=$_GET['location[horses-allowed]']; $Fence_woodA=$_GET['fence[wood]']; $Fence_ironA=$_GET['fence[iron]']; $Fence_brickA=$_GET['fence[brick]']; $Fence_rockA=$_GET['fence[rock]']; $Fence_automatic_gateA=$_GET['fence[automatic-gate]']; $Fence_noneA=$_GET['fence[none]']; $Special_requirementsA=$_GET['special_requirements']; $Properties_with_photosA=$_GET['properties_with[photos]']; $Single_detachedA=$_GET['property_types[single-detached]']; $MultiA=$_GET['property_types[multi]']; $TownhomeA=$_GET['property_types[townhome]']; $CondoA=$_GET['property_types[condo]']; $Half_duplexA=$_GET['property_types[half-duplex]']; $LeaseA=$_GET['property_types[lease]']; $Joseph_molinaA=$_GET['only[joseph-molina-properties]']; $Open_housesA=$_GET['only[open-houses]']; include("db.php"); $rets_login_url = "http://ntreisrets.mls.ntreis.net:80/rets/login"; $rets_username = "j_Kp$06$"; $rets_password = "$33D@E862"; $rets_agent = "JKP"; require_once('phRets.php'); $rets = new phRets; $connect = $rets->Connect($rets_login_url, $rets_username, $rets_password); if (!$connect) { print_r($rets->Error()); } ?> <body id="jrmolina-listing-detail" class="our-listings our-listings-landing" text> <div id="page"> <div id="content-container"> <div id="content" class="clearfix"> <div id="container"> <form action="<?php 'Search Results.php?op=Begin+Search&pg=' . 0 . '&property_Type='.urlencode($Property_Type).'&city='.$City.'&beds='.$Beds.'&baths='.$Baths.'&lowest_price='.$Lowest_Price.'&highest_price='.$Highest_Price; ?>" method="post" id="rha-mls-our-listings-sort"> <div id="rha-mls-our-listings-sort-container"> <label for="edit-sort-by" id="for-edit-sort-by"><span>Sort By</span> <select name="sort_by" class="form-select" id="edit-sort-by" ><option value="none">Choose one</option><option value="price-high-to-low">Price Highest to Lowest</option><option value="price-low-to-high">Price Lowest to Highest</option><option value="sqft-high-to-low">Size Largest to Smallest</option><option value="sqft-low-to-high">Size Smallest to Largest</option><option value="street-name-alpha">Street Name</option><option value="zip-code-numeric">Zip Code</option></select></label> <input type="submit" name="op" id="edit-submit" value="Go" class="form-submit" /> <input type="submit" name="op" id="edit-reset" value="Reset" class="form-submit" /> </div><!--/#rha-mls-our-listings-sort-container--> </form><!--/#rha-mls-our-listings-sort--> <input type="hidden" name="redirect" id="edit-redirect" value="/our-listings" /> <input type="hidden" name="page_count" id="edit-page-count" value="140" /> <input type="hidden" name="form_build_id" id="form-524b5209ac82045a8e3c250785a6e75b" value="form-524b5209ac82045a8e3c250785a6e75b" /> <input type="hidden" name="form_id" id="edit-rha-mls-pager" value="rha_mls_pager" /> <div id="listings-container"> <div id="listings"> <?php if(isset($_GET['sort'])){ $sort=$_GET['sort']; } else { $sort = "MODIFIED ASC"; } switch($_POST['sort_by']){ case "none": $sort = "MODIFIED ASC"; break; case "price-high-to-low": $sort = "LISTPRICE DESC"; break; case "price-low-to-high": $sort = "LISTPRICE ASC"; break; case "sqft-low-to-high": $sort = "SQFTTOTAL ASC"; break; case "sqft-high-to-low": $sort = "SQFTTOTAL DESC"; break; case "street-name-alpha": $sort = "STREETNAME ASC"; break; case "zip-code-numeric": $sort = "ZIPCODE ASC"; break; } if($Highest_Price==0 || $Highest_Price=="no_limit"){ if($Highest_Price=="no_limit"){$Highest_Price="5000000";} $Any= ">="; } else { $Any= "<="; } if($City==0){ $Any_City= ">"; } else { $Any_City= "LIKE"; } if($MLS==NULL){ $Any_MLS= "IS NOT"; } else { $Any_MLS= "="; } $result = mysql_query("SELECT * FROM residential WHERE PROPSUBTYPEDISPLAY LIKE '%{$Property_Type}%' AND AREA {$Any_City} {$City} AND BEDS >={$Beds} AND BATHSTOTAL >={$Baths} AND LISTPRICE >={$Lowest_Price} AND LISTPRICE {$Any} {$Highest_Price} ORDER BY {$sort} LIMIT {$offset}, {$limit}") or die(mysql_error()); ?> <div id="rha-mls-pager-container"> <?php mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM residential WHERE PROPSUBTYPEDISPLAY LIKE '%{$Property_Type}%' AND AREA {$Any_City} {$City} AND BEDS >={$Beds} AND BATHSTOTAL >={$Baths} AND LISTPRICE >={$Lowest_Price} AND LISTPRICE {$Any} {$Highest_Price} ORDER BY {$sort} LIMIT {$offset}, {$limit}"); $total_rows = mysql_query("SELECT FOUND_ROWS()"); $total_found = mysql_fetch_array($total_rows); $pages_count= $total_found[0] / $limit; $num_pages=intval($pages_count); echo $total_found[0]." results found"; echo "<br/>"; if ($pgnum > 0) { echo("<a href='Search Results.php?op=Begin+Search&pg=" . $prevpg ."&property_Type=".urlencode($Property_Type)."&city=".$City."&beds=".$Beds."&baths=".$Baths."&lowest_price=".$Lowest_Price."&highest_price=".$_GET['highest_price']."&sort=".$sort. "'><< Previous page</a> "); } if ($pgnum < $num_pages) { echo("<a href='Search Results.php?op=Begin+Search&pg=" . $nextpg . "&property_Type=".urlencode($Property_Type)."&city=".$City."&beds=".$Beds."&baths=".$Baths."&lowest_price=".$Lowest_Price."&highest_price=".$_GET['highest_price']."&sort=".$sort. "'>Next page >></a> "); } echo " "; echo ($pgnum+1)." out of ".($num_pages+1)." pages"; ?> </div><!--/#rha-mls-pager-container--> <br/> <?php while ($row = mysql_fetch_array($result)){ echo "<div class=\"vcard listing\">"; echo "<div class=\"information\">"; echo "<span class=\"listprice\">\$".number_format($row['LISTPRICE'])."\n </span><br/>"; echo "<p><span>{$row['STREETNUM']},{$row['STREETNAME']} "; echo "<BR/>{$row['CITY']}</span>"; echo "{$row['STATE']}, {$row['ZIPCODE']}</p>"; echo "<p><span>Beds: {$row['BEDS']}, Baths:{$row['BATHSTOTAL']}<br/>Square Feet: ".number_format($row['SQFTTOTAL'])." </span></p>"; echo "</div>"; $photos = $rets->GetObject("Property", "Photo", "{$row['MLSNUM']}", "0", 1); foreach ($photos as $photo) { $listing = $photo['Content-ID']; $number = $photo['Object-ID']; if ($photo['Success'] == true) { echo "<img src='{$photo['Location']}\n' alt=\"\" title=\"\" class=\"listing-photo photo\" width=\"146\" height=\"107\" />"; echo "<a href=\"PropDetails.php?pg=" . $pgnum ."&property_Type=".$Property_Type."&city=".$City."&beds=".$Beds."&baths=".$Baths."&lowest_price=".$Lowest_Price."&highest_price=".$Highest_Price."&MLS=".$row['MLSNUM'].$mainp."#{$photo['Location']}"."\" class=\"button url\">Property Details</a>"; } else { echo "<img src='images/no-image.png' alt=\"\" title=\"\" class=\"listing-photo photo\" width=\"146\" height=\"107\" />"; echo "<a href=\"PropDetails.php?MLS={$row['MLSNUM']}\" class=\"button url\">See Property Details</a>"; } } echo "</div>"; } ?> </div> </div> </div> </div> </div> </div> </body> </head> </html> Any ideas guys??? Quote Link to comment https://forums.phpfreaks.com/topic/206590-parse-error/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 3, 2010 Share Posted July 3, 2010 It's likely that $Any_City or $City is either empty or contains some un-escaped special characters that are breaking the sql syntax of the query. I recommend forming your sql query in a php variable (such as $query) so that you can echo it out to see exactly what it contains. Quote Link to comment https://forums.phpfreaks.com/topic/206590-parse-error/#findComment-1080535 Share on other sites More sharing options...
hybmg57 Posted July 3, 2010 Author Share Posted July 3, 2010 Hi I have a search form that I created and trying to parse info entered from advanced search form to the search results page and I get this error... You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND BEDS >=0 AND BATHSTOTAL >=0 AND LISTPRICE >=0 AND LI' at line 5 Here is the code for the search results page... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>JR Molina</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="robots" content="index,follow" /> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /> <link rel="apple-touch-icon" href="/apple-touch-icon.png"/> <link charset="utf-8" type="text/css" rel="stylesheet" media="all" href="results.css" /> <?php if (is_numeric($_GET['pg'])) { $pgnum = ((int) $_GET['pg']); } else { $pgnum = 0; $errorMessage = "Invalid value for page number"; } $startnum = 1; $nextpg = ($pgnum + 1); $prevpg = ($pgnum-1); if ($pgnum >= 0) { $offset = ($pgnum * 20); } else { $offset = 0; } $limit = 20; ?> <?php $Property_Type=$_GET['property_type']; $City=$_GET['city']; $Beds=$_GET['beds']; $Baths=$_GET['baths']; $Lowest_Price=$_GET['lowest_price']; $Highest_Price=$_GET['highest_price']; $MLS=$_GET['mls_number']; $AddressA=$_GET['address']; $Zip_codeA=$_GET['zip_code']; $SubdivisionA=$_GET['subdivision']; $GarageA=$_GET['garage']; $StoriesA=$_GET['stories']; $FireplacesA=$_GET['fireplaces']; $Yard_sizeA=$_GET['yard_size']; $CitiesA=$_GET['cities']; $AreasA=$_GET['areas']; $CountiesA=$_GET['counties']; $School_districtA=$_GET['school_district']; $School_elementaryA=$_GET['school_type[elementary]']; $School_middleA=$_GET['school_type[middle]']; $School_highA=$_GET['school_type[high]']; $School_nameA=$_GET['school_name']; $Guest_quartersA=$_GET['property[guest-quarters]']; $High_riseA=$_GET['property[high-rise-condominium]']; $Loft_A=$_GET['property[loft]']; $BalconyA=$_GET['property[balcony]']; $LibraryA=$_GET['property[library-or-study]']; $MediaA=$_GET['property[media-room]']; $Gated_communityA=$_GET['location[gated-community]']; $Golf_course_communityA=$_GET['location[golf-course-community]']; $Golf_course_lotA=$_GET['location[golf-course-lot]']; $Lake_front_lotA=$_GET['location[lake-front-lot]']; $Lake_viewA=$_GET['location[lake-view]']; $Handicap_amenitiesA=$_GET['location[handicap-ammenities]']; $Zero_lot_lineA=$_GET['location[zero-lot-line]']; $Horses_allowedA=$_GET['location[horses-allowed]']; $Fence_woodA=$_GET['fence[wood]']; $Fence_ironA=$_GET['fence[iron]']; $Fence_brickA=$_GET['fence[brick]']; $Fence_rockA=$_GET['fence[rock]']; $Fence_automatic_gateA=$_GET['fence[automatic-gate]']; $Fence_noneA=$_GET['fence[none]']; $Special_requirementsA=$_GET['special_requirements']; $Properties_with_photosA=$_GET['properties_with[photos]']; $Single_detachedA=$_GET['property_types[single-detached]']; $MultiA=$_GET['property_types[multi]']; $TownhomeA=$_GET['property_types[townhome]']; $CondoA=$_GET['property_types[condo]']; $Half_duplexA=$_GET['property_types[half-duplex]']; $LeaseA=$_GET['property_types[lease]']; $Joseph_molinaA=$_GET['only[joseph-molina-properties]']; $Open_housesA=$_GET['only[open-houses]']; include("db.php"); $rets_login_url = "http://ntreisrets.mls.ntreis.net:80/rets/login"; $rets_username = "user"; $rets_password = "password"; $rets_agent = "JKP"; require_once('phRets.php'); $rets = new phRets; $connect = $rets->Connect($rets_login_url, $rets_username, $rets_password); if (!$connect) { print_r($rets->Error()); } ?> <body id="jrmolina-listing-detail" class="our-listings our-listings-landing" text> <div id="page"> <div id="content-container"> <div id="content" class="clearfix"> <div id="container"> <form action="<?php 'Search Results.php?op=Begin+Search&pg=' . 0 . '&property_Type='.urlencode($Property_Type).'&city='.$City.'&beds='.$Beds.'&baths='.$Baths.'&lowest_price='.$Lowest_Price.'&highest_price='.$Highest_Price; ?>" method="post" id="rha-mls-our-listings-sort"> <div id="rha-mls-our-listings-sort-container"> <label for="edit-sort-by" id="for-edit-sort-by"><span>Sort By</span> <select name="sort_by" class="form-select" id="edit-sort-by" ><option value="none">Choose one</option><option value="price-high-to-low">Price Highest to Lowest</option><option value="price-low-to-high">Price Lowest to Highest</option><option value="sqft-high-to-low">Size Largest to Smallest</option><option value="sqft-low-to-high">Size Smallest to Largest</option><option value="street-name-alpha">Street Name</option><option value="zip-code-numeric">Zip Code</option></select></label> <input type="submit" name="op" id="edit-submit" value="Go" class="form-submit" /> <input type="submit" name="op" id="edit-reset" value="Reset" class="form-submit" /> </div><!--/#rha-mls-our-listings-sort-container--> </form><!--/#rha-mls-our-listings-sort--> <input type="hidden" name="redirect" id="edit-redirect" value="/our-listings" /> <input type="hidden" name="page_count" id="edit-page-count" value="140" /> <input type="hidden" name="form_build_id" id="form-524b5209ac82045a8e3c250785a6e75b" value="form-524b5209ac82045a8e3c250785a6e75b" /> <input type="hidden" name="form_id" id="edit-rha-mls-pager" value="rha_mls_pager" /> <div id="listings-container"> <div id="listings"> <?php if(isset($_GET['sort'])){ $sort=$_GET['sort']; } else { $sort = "MODIFIED ASC"; } switch($_POST['sort_by']){ case "none": $sort = "MODIFIED ASC"; break; case "price-high-to-low": $sort = "LISTPRICE DESC"; break; case "price-low-to-high": $sort = "LISTPRICE ASC"; break; case "sqft-low-to-high": $sort = "SQFTTOTAL ASC"; break; case "sqft-high-to-low": $sort = "SQFTTOTAL DESC"; break; case "street-name-alpha": $sort = "STREETNAME ASC"; break; case "zip-code-numeric": $sort = "ZIPCODE ASC"; break; } if($Highest_Price==0 || $Highest_Price=="no_limit"){ if($Highest_Price=="no_limit"){$Highest_Price="5000000";} $Any= ">="; } else { $Any= "<="; } if($City==0){ $Any_City= ">"; } else { $Any_City= "LIKE"; } if($MLS==NULL){ $Any_MLS= "IS NOT"; } else { $Any_MLS= "="; } $result = mysql_query("SELECT * FROM residential WHERE PROPSUBTYPEDISPLAY LIKE '%{$Property_Type}%' AND AREA {$Any_City} {$City} AND BEDS >={$Beds} AND BATHSTOTAL >={$Baths} AND LISTPRICE >={$Lowest_Price} AND LISTPRICE {$Any} {$Highest_Price} ORDER BY {$sort} LIMIT {$offset}, {$limit}") or die(mysql_error()); ?> <div id="rha-mls-pager-container"> <?php mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM residential WHERE PROPSUBTYPEDISPLAY LIKE '%{$Property_Type}%' AND AREA {$Any_City} {$City} AND BEDS >={$Beds} AND BATHSTOTAL >={$Baths} AND LISTPRICE >={$Lowest_Price} AND LISTPRICE {$Any} {$Highest_Price} ORDER BY {$sort} LIMIT {$offset}, {$limit}"); $total_rows = mysql_query("SELECT FOUND_ROWS()"); $total_found = mysql_fetch_array($total_rows); $pages_count= $total_found[0] / $limit; $num_pages=intval($pages_count); echo $total_found[0]." results found"; echo "<br/>"; if ($pgnum > 0) { echo("<a href='Search Results.php?op=Begin+Search&pg=" . $prevpg ."&property_Type=".urlencode($Property_Type)."&city=".$City."&beds=".$Beds."&baths=".$Baths."&lowest_price=".$Lowest_Price."&highest_price=".$_GET['highest_price']."&sort=".$sort. "'><< Previous page</a> "); } if ($pgnum < $num_pages) { echo("<a href='Search Results.php?op=Begin+Search&pg=" . $nextpg . "&property_Type=".urlencode($Property_Type)."&city=".$City."&beds=".$Beds."&baths=".$Baths."&lowest_price=".$Lowest_Price."&highest_price=".$_GET['highest_price']."&sort=".$sort. "'>Next page >></a> "); } echo " "; echo ($pgnum+1)." out of ".($num_pages+1)." pages"; ?> </div><!--/#rha-mls-pager-container--> <br/> <?php while ($row = mysql_fetch_array($result)){ echo "<div class=\"vcard listing\">"; echo "<div class=\"information\">"; echo "<span class=\"listprice\">\$".number_format($row['LISTPRICE'])."\n </span><br/>"; echo "<p><span>{$row['STREETNUM']},{$row['STREETNAME']} "; echo "<BR/>{$row['CITY']}</span>"; echo "{$row['STATE']}, {$row['ZIPCODE']}</p>"; echo "<p><span>Beds: {$row['BEDS']}, Baths:{$row['BATHSTOTAL']}<br/>Square Feet: ".number_format($row['SQFTTOTAL'])." </span></p>"; echo "</div>"; $photos = $rets->GetObject("Property", "Photo", "{$row['MLSNUM']}", "0", 1); foreach ($photos as $photo) { $listing = $photo['Content-ID']; $number = $photo['Object-ID']; if ($photo['Success'] == true) { echo "<img src='{$photo['Location']}\n' alt=\"\" title=\"\" class=\"listing-photo photo\" width=\"146\" height=\"107\" />"; echo "<a href=\"PropDetails.php?pg=" . $pgnum ."&property_Type=".$Property_Type."&city=".$City."&beds=".$Beds."&baths=".$Baths."&lowest_price=".$Lowest_Price."&highest_price=".$Highest_Price."&MLS=".$row['MLSNUM'].$mainp."#{$photo['Location']}"."\" class=\"button url\">Property Details</a>"; } else { echo "<img src='images/no-image.png' alt=\"\" title=\"\" class=\"listing-photo photo\" width=\"146\" height=\"107\" />"; echo "<a href=\"PropDetails.php?MLS={$row['MLSNUM']}\" class=\"button url\">See Property Details</a>"; } } echo "</div>"; } ?> </div> </div> </div> </div> </div> </div> </body> </head> </html> Any ideas guys??? Quote Link to comment https://forums.phpfreaks.com/topic/206590-parse-error/#findComment-1080548 Share on other sites More sharing options...
hybmg57 Posted July 3, 2010 Author Share Posted July 3, 2010 Hi, thanks for your reply. It seems like I'm having an issue with parsing something must be one of below... Please have a look at this link and do a search... http://test1.favstay.com/Advanced_Search.php Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/206590-parse-error/#findComment-1080563 Share on other sites More sharing options...
hybmg57 Posted July 3, 2010 Author Share Posted July 3, 2010 I still seem to have problems, is there any other advice out there please??? Quote Link to comment https://forums.phpfreaks.com/topic/206590-parse-error/#findComment-1080863 Share on other sites More sharing options...
PFMaBiSmAd Posted July 3, 2010 Share Posted July 3, 2010 is there any other advice out there please Yes, read and follow the last advice you were given to troubleshoot why your query is producing an error. Quote Link to comment https://forums.phpfreaks.com/topic/206590-parse-error/#findComment-1080865 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.