PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
$soldhousesquery = "SELECT Price, HouseType FROM soldhouses ORDER BY Price ASC";
$soldhousesresult = @mysql_query($soldhousesquery) or die(mysql_error());
while($soldhousesrow = mysql_fetch_array($soldhousesresult)) {
echo "<option value=\"{$soldhousesrow['Price']}\">£ {$soldhousesrow['Price']} - {$soldhousesrow['HouseType']}</option>";
}
?>
And im trying to work out how to obtain the choice the user has picked and to put them into a variable ready for inserting into the database.
Firstly there are two values in the list box that are included these are "Price" and "House Type". How would i get the user's choice in to two variables as $Price and $HouseType?
<?php
$price = 0;
$houseType = '';
if (isset($_POST['users_choice']))
{
$val = $_POST['users_choice'];
$pos = strpos($val, '|');
if ($pos !== false)
{
//Price of the house is before | symbol
$price = substr($val, 0, $pos);
//House type is after | symbol
$houseType = substr($val, $pos+1);
}
}
?>
Edit:
On page2.php house price and type is received from user, so you can't be sure that these are the same values which you took from database.
Instead of putting in the select box price and house type, you should put primary (unique) key of the data from database.