Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP/MySQL search not working
    primarykey
    data
    text
    <p>I am having some difficulty with my PHP/MySQL search. It worked great a year ago, but for some reason it has just stopped working. I have tried searching and cannot figure it out. I have it echo my query but it never adds in the WHERE clause. Any help is much appreciated.</p> <p>Form Code:</p> <pre><code>&lt;form name="search" method="post"&gt; &lt;p&gt;&lt;b&gt;Name of Property:&lt;/b&gt; &lt;input type="text" id="NameSrch" name="NameSrch" /&gt; (optional)&lt;/p&gt; &lt;p&gt;&lt;b&gt;City Your Looking to Stay In:&lt;/b&gt; &lt;input type="text" id="CitySrch" name="CitySrch" /&gt; (optional)&lt;/p&gt; &lt;p&gt;&lt;b&gt;Listing ID Number:&lt;/b&gt; &lt;input type="text" id="RentalIDSrch" name="RentalIDSrch" /&gt; (optional)&lt;/p&gt; &lt;p&gt;&lt;b&gt;Number of Bedrooms:&lt;/b&gt; &lt;input type="text" id="BedroomSrch" name="BedroomSrch" /&gt; (optional)&lt;/p&gt; &lt;p&gt;&lt;b&gt;Number of Bathrooms:&lt;/b&gt; &lt;input type="text" id="BathroomSrch" name="BathroomSrch" /&gt; (optional)&lt;/p&gt; &lt;p&gt;&lt;b&gt;Maximum Occupancy:&lt;/b&gt; &lt;input type="text" id="SleepsSrch" name="SleepsSrch" /&gt; (optional)&lt;/p&gt; &lt;input type="hidden" name="method" value="exSearch"&gt; &lt;p&gt;&lt;input type="submit" value="Search" /&gt;&lt;/p&gt; &lt;/form&gt; </code></pre> <p>PHP Code:</p> <pre><code>&lt;? $method = $_POST['method']; if($method == 'exSearch') { // Start Results Display $con = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql: ' . mysql_error()); mysql_select_db($dbname); $query_string = 'SELECT * FROM TABLE '; $location_result_string = ""; $location_count = 0; if ($NameSrch) { if ($location_count &gt; 0) { $location_result_string = $location_result_string . " AND "; } $location_count = $location_count + 1; $location_result_string = $location_result_string . ' (propName) LIKE ("%$NameSrch%") '; } if ($CitySrch) { if ($location_count &gt; 0) { $location_result_string = $location_result_string . " AND "; } $location_count = $location_count + 1; $location_result_string = $location_result_string . ' (propCity) LIKE ("%$CitySrch%") '; } if ($RentalIDSrch) { if ($location_count &gt; 0) { $location_result_string = $location_result_string . " AND "; } $location_count = $location_count + 1; $location_result_string = $location_result_string . ' (propID) LIKE ("%$RentalIDSrch%") '; } if ($BedroomSrch) { if ($location_count &gt; 0) { $location_result_string = $location_result_string . " AND "; } $location_count = $location_count + 1; $location_result_string = $location_result_string . ' (propBedrooms) LIKE ("%$BedroomSrch%") '; } if ($BathroomSrch) { if ($location_count &gt; 0) { $location_result_string = $location_result_string . " AND "; } $location_count = $location_count + 1; $location_result_string = $location_result_string . ' (propBaths) LIKE ("%$BathroomSrch%") '; } if ($SleepsSrch) { if ($location_count &gt; 0) { $location_result_string = $location_result_string . " AND "; } $location_count = $location_count + 1; $location_result_string = $location_result_string . ' (propSleeps) LIKE ("%$SleepsSrch%") '; } if ($location_count &gt; 0) { $location_result_string = "WHERE (" . $location_result_string . ")"; $query_string = $query_string . $location_result_string; } $re = mysql_query($query_string, $con) or die (mysql_error()); $number_of_rows = mysql_num_rows($re); // Loop through each item in the result set for ($h = 0; $h &lt; $number_of_rows; $h++) { $propID = mysql_result($re, $h, 'propID'); $propAvail = mysql_result($re, $h, 'propAvail'); $propPets = mysql_result($re, $h, 'propPets'); $propName = mysql_result($re, $h, 'propName'); $propPropertyType = mysql_result($re, $h, 'propPropertyType'); $propPriceRange = mysql_result($re, $h, 'propPriceRange'); $propBedrooms = mysql_result($re, $h, 'propBedrooms'); $propBaths = mysql_result($re, $h, 'propBaths'); $propPropertyType = mysql_result($re, $h, 'propPropertyType'); $propSleeps = mysql_result($re, $h, 'propSleeps'); $propPic1 = mysql_result($re, $h, 'propPic1'); $propPicDesc1 = mysql_result($re, $h, 'propPicDesc1'); $nameLen = strlen($propName); $petsLen = strlen($propPets); $pets = $propPets; //Results go here } echo $query_string; } // End Results Display ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload