Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- Search and Empty PHP


Adamphp - 7:44 pm on Feb 7, 2012 (gmt 0)


I need help with processing this form

It works but i want to the submit to search the whole db if nothing is selected to value of ""

Also is this the correct way to process a search form for searching cars or is there a more pro way

HTML
Make = Make
Model = Model
Min Price = Name "pf"
Max Price = Name "pt"

PHP
----

<body>


<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

// include you database connect file with username etc.
include ("db.php");

//Connect to the database using values from db.php ajones_cardealer $database variable value from db.php
$connect = mysql_connect($host,$username,$password) or die('<p class="error">Unable to connect to the database server at this tim</p>');

//select the database we are going to use in this case its
mysql_select_db($database,$connect) or die('<p class="error">Unable to connect to the database at this time.</p>');

// Get the posted value based on option select.

$Make = $_POST['make'];
$Min_Price = $_POST['pf'];
$Max_Price = $_POST['pt'];

//Uncomment below to check post is working.
//echo $Make;

// Create SQL query to find the row with make_id.
$query = "SELECT * FROM site_cars WHERE car_Make = $Make AND car_price BETWEEN $Min_Price AND $Max_Price";

//Run Query and store values in the $result array.
$result = @mysql_query("$query") or die('<p class="error">There was an unexpected error grabbing comments from the database.</p>');

//output results

?>

<table>
<tr>
<td>
<?php
if ($result != false)
{
while ($car = mysql_fetch_array ($result) )
{ // close the php here so you can write your html easier.?>

<!-- write your html here -->
<table>
<table>
<tr>
<td><img height="100" width="100"/>
</td>
<td valign="top">
<table>
<tr>
<td>
REF: <?php echo $car['car_id'];?>
</td>
</tr>
<tr>
<td>
Make
</td>
<td>
<?php echo $car["car_make"]; ?>
</td>
</tr>
<tr>
<td>
Price
</td>
<td>
&pound; <?php echo $car['car_price'] = number_format($car["car_price"] , 2);;?>
</td>
</tr>
<tr>
<td>
Milage
</td>
<td>
<?php echo $car['car_mileage'];?>
</td>
</tr>
<tr>
<td>
Year
</td>
<td>
<?php echo $car['car_year'];?>
</td>
</tr>
</table>
</td>
<td style="padding-left:10px;" valign="top">
<?php echo $car['car_description'];?>
</td>
</tr>
</table>
</table>

<?php // open your php again here to close the while and if statements.
}
}?>

</td>
</tr>
</table>

</body>
</html>


Thread source:: http://www.webmasterworld.com/php/4415167.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com