Jump to content
Sign in to follow this  
adam.jones2

Processing HTML Search Form

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

Edited by adam.jones2

Share this post


Link to post
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().

Share this post


Link to post
Share on other sites

Thanks i have taken you advice and updated the phpstill no feature where it searches the whole database if all value = "" also no feature where if i select Min price only it will search everything above that price range updates php attached

quicksearch.php

Edited by adam.jones2

Share this post


Link to post
Share on other sites

Well, you need to add a bit of PHP to modify the query in those cases. It's nothing more than a few if() conditions. It shouldn't be too hard.

Share this post


Link to post
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);}?>

Edited by adam.jones2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...