Hmm look here, well you are setting $target to the POST var, but in the header location your using $url. This is a bit confusing, so:
1) User selects item from down down
2) That is posted to div.php as url
Now this is where the confusion begins, do we use the value of $url to make a second call to the database to grab the URL? Or do we simply send them to value of
$url? I would move the connection info into a separate file and simply require that in the first script.
db_conn.php
<?php
define('DB_HOST', 'hostname');
define('DB_USER', 'username');
define('DB_PASS', 'password');
define('DB_DBASE', 'database');
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Could not connect: " . mysql_error());
mysql_select_db(DB_DBASE, $conn);
functions.php
<?php
// require our db file
require_once('db_conn.php');
function getWebUrls() {
$sql = "SELECT id, webname, url FROM mytable";
$result = mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
$ret[]=data;
}
return $ret;
}
first file:
<?php
error_reporting(E_ALL && ~E_NOTICES);
// require our functions file
require_once('functions.php');
// if user selected url, redirect them there
if (!empty($_POST['url'])) {
header('Location: '.$_POST['url']);
}
$link_item = getWebUrls();
?>
<form method="post" action="">
<select name="url">
<? foreach ($ret as $key => $value): ?>
<option value ="<? $link_item['url']; ?>"><? $link_item['webname']; ?></option>
<? endforeach; ?>
</select>
<input type="submit" name="submit" value="Go!" /></form>
</form>
Keep in mind you could do the redirect with javascript onChange... lots of other things you could do to simplify and clean up. This is just an idea for better oragnization.