Hi! I wrote a page to have 3 drop-downs based on car year, make and model data in a MySQL database. The 3 drop-downs are dependent on one another. The problem is with the second drop-down selection. The logic works fine if the selected value is a single word but doesn't work if there is a space in between any of the words.
Example that works: Year selected is 1981. Make selected is Audi. The third drop-down shows all the models for 1981 Audi's.
Example showing the problem: Year selected is 1981. Make selected is American Motors. The third drop-down fails because the value passed from the second drop-down is "American", not "American Motors" so the third drop-down is bombing because it's not finding a corresponding model for "American". I know the value is correct coming from the database because I see "American Motors" as a selection in the second drop-down but the "Motors" part is being lost somewhere from the click to when it is read by the submit.
Here's my code for the second drop-down. I have done all the drop-downs in the same way. I can tell by testing that the "Motors" part is not there by the time it gets to the sql statement for the final drop-down.
echo "<p align='left'>Vehicle Make: ";
if ($_POST['VehicleYear'] != "")
{
$query='SELECT distinct vehiclemake FROM vehicledata WHERE vehicleyear = '.$_POST['VehicleYear'];
$result=mysql_query($query);
$num_results = mysql_num_rows($result) or die ("num result failed ln 55");
echo '<select name="VehicleMake" onchange="this.form.submit()">';
echo '<option value="Select Make" selected>Select Make</option>';
$vehyear = $_POST['VehicleYear'];
$vehmake = isset($_POST["VehicleMake"]) ? $_POST["VehicleMake"] : "";
if ($vehmake == "")
{
$makeselected = "Select Make";
}
else
{
$makeselected = $vehmake;
}
for ($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
$make = stripslashes($row['vehiclemake']);
if ($make == $makeselected)
{
echo "<option value=$make selected>$make</option><br>";
}
else
{
echo "<option value=$make>$make</option><br>";
}
}
echo "</select><br><br><br>";
} //end of main if on make section
echo "</p>";
Thanks for your help.
Alexis
Example that works: Year selected is 1981. Make selected is Audi. The third drop-down shows all the models for 1981 Audi's.
Example showing the problem: Year selected is 1981. Make selected is American Motors. The third drop-down fails because the value passed from the second drop-down is "American", not "American Motors" so the third drop-down is bombing because it's not finding a corresponding model for "American". I know the value is correct coming from the database because I see "American Motors" as a selection in the second drop-down but the "Motors" part is being lost somewhere from the click to when it is read by the submit.
Here's my code for the second drop-down. I have done all the drop-downs in the same way. I can tell by testing that the "Motors" part is not there by the time it gets to the sql statement for the final drop-down.
echo "<p align='left'>Vehicle Make: ";
if ($_POST['VehicleYear'] != "")
{
$query='SELECT distinct vehiclemake FROM vehicledata WHERE vehicleyear = '.$_POST['VehicleYear'];
$result=mysql_query($query);
$num_results = mysql_num_rows($result) or die ("num result failed ln 55");
echo '<select name="VehicleMake" onchange="this.form.submit()">';
echo '<option value="Select Make" selected>Select Make</option>';
$vehyear = $_POST['VehicleYear'];
$vehmake = isset($_POST["VehicleMake"]) ? $_POST["VehicleMake"] : "";
if ($vehmake == "")
{
$makeselected = "Select Make";
}
else
{
$makeselected = $vehmake;
}
for ($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
$make = stripslashes($row['vehiclemake']);
if ($make == $makeselected)
{
echo "<option value=$make selected>$make</option><br>";
}
else
{
echo "<option value=$make>$make</option><br>";
}
}
echo "</select><br><br><br>";
} //end of main if on make section
echo "</p>";
Thanks for your help.
Alexis