Forum Moderators: coopster
<html>
<head><title>List DB</title></head>
<body>
<form method="POST" action="test.php"><div> align="center"><center><p>Select Db
<input type="hidden" name="db_name" value="DB_names">
<SELECT NAME="Select DB">
<?php
$conn = @mysql_connect( 'myserver', 'myuser', 'mypass' )
or die( mysql_errno().': '.mysql_error().
$result = mysql_list_dbs( $conn );
while( $row = mysql_fetch_object( $result ) ):
echo "<option value=\"$row->Database\">$row->Database</option>";
endwhile;
// Free resources / close MySQL Connection
mysql_free_result( $result );
mysql_close( $conn );
?>
</select>
<input type="submit" value="Submit"></center></div>
</form>
</body>
</html>
In your 'test.php' script, you should be able to access the variable like so:
print $_POST['Select_DB'];
<SELECT NAME="Select_DB">
<?php$conn = @mysql_connect( 'myserver', 'myuser', 'mypass' )
or die( mysql_errno().': '.mysql_error(); // <-semicolon here
$result = mysql_list_dbs( $conn );while( $row = mysql_fetch_object( $result ) ):
echo "<option value=\"$row->Database\">$row->Database</option>";
endwhile;// Free resources / close MySQL Connection
mysql_free_result( $result );
mysql_close( $conn );?>
<SELECT NAME="Select_DB">
<?php
$conn = @mysql_connect( 'myserver', 'myuser', 'mypass' )
or die( mysql_errno().': '.mysql_error());
$result = mysql_list_dbs( $conn );
while( $row = mysql_fetch_object( $result ) ):
echo "<option value=\"$row->Database\">$row->Database</option>";
endwhile;
// Free resources / close MySQL Connection
mysql_free_result( $result );
mysql_close( $conn );
?>
[edited by: Birdman at 3:05 pm (utc) on Oct. 19, 2006]