I have a dropdown on a page. I wish to publish the selected option as a link to another web page. If a user selects Kenya in the code below, for example, the value is stored in a database and then the record is retrieved and published as a link to a certain page. See code below:
HTML:
<select name="country" id="country">
<option value="kenya">Kenya</option>
<option value="uganda">Uganda</option>
</select>
PHP/SQL
//Data saving
$user_country = $_POST['country']);
$sql = "INSERT INTO countries (country_name)
VALUES ($user_country)";
//publishing the saved data as a link
$sql = "SELECT user_country FROM countrydb";
$result = $conn->query($sql);
if ($result->num_rows > 0) && ($row["user_country"] = "kenya") {
while($row = $result->fetch_assoc()) {
echo '<a href="kenya.php"> Kenya</a>';
}
}
elseif ($result->num_rows > 0) && ($row["user_country"] = "uganda") {
while($row = $result->fetch_assoc()) {
echo '<a href="uganda.php">Uganda</a>';
}
}
else {
echo "no results";
}