So, this is a "next step" for me learning how to pass multiple variables from a form to a database and publish the results. I feel that I'm *holds fingers in air* this close, but the actual solution is alluding me.
Goal: To have user select from dropdown list of 4 variables and have the query show results of that query. If there is nothing selected, show all.
Knowledge: Quite used to working and modifying other peoples scripts. First time connecting raw script to a database. I've moderate knowledge of passing variables with GET and POST from form to another page. And have knowledge of some PHP scripting and syntax.
Form Script:
<form action="houseplan_results.php" method="get" name="house plans" id="house plans">
<div class="houseplans">
Type of House Plan:
<select name="houseplans">
<option selected="selected" value="All Types">All Types</option>
<option value="Beach/Coastal">Beach/Coastal</option>
<option value="Bungalow">Bungalow</option>
<option value="Contemporary">Contemporary</option>
<option value="Country">Country</option>
<option value="Craftsman">Craftsman</option>
<option value="European">European</option>
<option value="French">French</option>
<option value="Modern">Modern</option>
<option value="Northwest">Northwest</option>
<option value="Ranch">Ranch</option>
<option value="Victorian">Victorian</option>
<option value="Commercial">Commercial</option>
</select>
</div>
<div class="listbox">
Number of Bedrooms:
<select name="bedrooms">
<option selected="selected" value="">Any</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="13">13</option>
</select>
</div>
<div class="listbox">
Number of Bathrooms:
<select name="bathrooms">
<option selected="selected" value="">Any</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="1.5">1.5</option>
<option value="2">2</option>
<option value="2.5">2.5</option>
<option value="3">3</option>
<option value="3.5">3.5</option>
<option value="4">4</option>
<option value="4.5">4.5</option>
<option value="4.5 +.5">4.5 +.5</option>
<option value="5.5">5.5</option>
<option value="7">7</option>
<option value="7.5">7.5</option>
<option value="12.5">12.5</option>
</select>
</div>
<div class="listbox">
Number of Garages:
<select name="garages">
<option selected="selected" value="">Any</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
</div>
<input name="Search" type="submit" />
</form>
and Result Page/Query Page. (note I do have mysql connection page setup and that is working)
<?php require_once('Connections/plansdb.php'); ?>
<?php
//variables from submit form
$houseplans = $plantypes ;
$bedrooms = $bed ;
$bathrooms = $bath ;
$garages = $garage ;
// Query DB
$query = sprintf("SELECT PLANNO, PLANTYPES, DESC, BED, BATH, GARAGE, FLOORS, URL, IMG FROM plans WHERE PLANTYPES='%s' AND BED='%s' AND BATH='%s' AND GARAGE='%s'",
mysql_real_escape_string($plantypes),
mysql_real_escape_string($bed),
mysql_real_escape_string($bath),
mysql_real_escape_string($garage));
// Perform Query
$result = mysql_query($query);
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
// Use result
while ($row = mysql_fetch_assoc($result)) {
echo $row['PLANNO'];
echo $row['PLANTYPES'];
echo $row['DESC'];
echo $row['BED'];
echo $row['BATH'];
echo $row['GARAGE'];
echo $row['FLOORS'];
echo $row['URL'];
echo $row['IMG'];
}
mysql_free_result($result);
?>
resource PHP.net mysql_query()
So - after a good attempt, I'm stuck. I'm thinking I've got my variables all mixed up - but need a tip/direction/solution on how to fix this.
Thanks
Jade