As already stated, the undefined variable is due to your page getting an empty $_POST result as long as the first form has not been submitted. For your switch to work, you have to hit a submit button (which currently does not exist, unfortunately :)), so that the page reloads with the proper POST data.
I assume you might want something like this:
<?php
if(isset($_POST['destination']))
{
$destinations = array (
"Data1" => "Data1Value",
"Data2" => "Data2Value",
"Data3" => "Data3Value");
$dest = $destinations[$_POST['destination']];
echo "<p>destination set from POST vars: <b>$dest</b></p><br />";
// do whatever you want with your destination
// (presumably redirect to another page)
// travel_to ($dest);
die(); // redirecting should make you leave the page
}
?>
<form method="POST">
<select name="destination">
<option value="Data1">Data1</option>
<option value="Data2">Data2</option>
<option value="Data3">Data3</option>
</select>
<input type='submit' value='Travel!'>
</form>
A few comments:
- renamed "dropdown" to something more meaningful. Bad names make bad code.
- added the submit button without which you could never send the form (except with the help of some JavaScript, but that's another story)
- removed the hidden input, which I think was showing a bit of confusion between the initial page (where the select defines your destination) and the final page (where the POST data retrieves the destination via the select value)
- replaced the switch with an array. Associative array are the bread and butter of PHP (well, among other things :)). Better get used to them as quick as possible, you very probably won't regret it.
Note that the page doing the input and the one processing the POST data are often two separate HTML/PHP files. Doing both from the same file is easier to test, but might be a bit confusing.
EDIT:
Fiddling with databases is an entirely different question, and I could get scolded for straying way off topic but, for the sake of completeness, here is a rough sketch of what you could do.
Note that you will have to create the database and the table that will hold the record.
Note also that this code will not run out of the box.
You will have to fill-in the blanks by yourself, using the PHP manual.
Especially, I left error handling out for concision.
<?php
if(isset($_POST['value_selector']))
{
$data_values = array (
"Data1" => "Data1Value",
"Data2" => "Data2Value",
"Data3" => "Data3Value");
$value = $data_values[$_POST['value_selector']];
// now that you've got your value, let's cram it into a DB!
// see PHP manual for details
// --------------------------
// you'll need to create a base named "database"
// with a table named "data_table"
// containing a field named "data"
// and provide a host, user name & password for the MySQL connection
//
$DBH = new PDO("mysql:host=$host;dbname=database", $user, $pass);
$DBH->exec("INSERT INTO data_table ( data ) values ( '$value' )");
// done!
echo "<p>value of <b>data</b> set from POST vars to <b>$value</b></p><br />";
die();
}
?>
<form method="POST">
<select name="value_selector">
<option value="Data1">Data1</option>
<option value="Data2">Data2</option>
<option value="Data3">Data3</option>
</select>
<input type='submit' value='Store that data!'>
</form>
$input?