Jump to content

Processing HTML Search Form


adam.jones2

Recommended Posts

I need to create a search.php Whats the best practice for this? Search options are Make, Model, Min Price - Max Price I have attached what i have done so fare which works but not how i want Features i want is that if nothing is selected then it search the whole db also if only price is select it will return the results I have searched Google and surprised there not much info on this example search engine im looking for is http://www.motors.co.uk/

quicksearch.php

Link to comment
Share on other sites

You haven't sanitized the input. People can use your code to hack the database. You should be using mysql_real_escape_string() on the input data. You should also get out of the habit of putting quotation marks around variable names like here: @mysql_query("$query") You seem to have it all working. All you need to do is take the results of the query and loop through them. W3Schools' PHP tutorial shows how to do that pretty well. though I prefer mysql_fetch_assoc() rather than mysql_fetch_array().

Link to comment
Share on other sites

This what i have but does not workThis Just searches everythingplease help

<?php$Make = $_POST['make']; // would equal Car name or ""$Min_Price = $_POST['pf'];$Max_Price = $_POST['pt'];$query = "SELECT * FROM site_cars";$result=mysql_query ($query);$filter = array();if (!empty($Make)) {$filter[] = "car_Make = $Make";}if (!empty($Min_Price)) {$filter[] = "car_price = $Min_Price";}if (!empty($Max_Price)) {$filter[] = "car_price = $Max_Price";}if (!empty($filters)) {$query .= ' WHERE ' . implode(' AND ', $filters);}?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...