gentlebreeze gentlebreeze - 5 months ago 9x
PHP Question

dropdown to show table in DB

I am working on the following code where the user chooses a table from a dropdown. On change, it displays the table but at the moment it is echoing some of the code to screen.

$dbh = "localhost";
$dbn = "dbname";
$dbu = "dbuser";
$dbp = "dbpassword";

$conn = mysql_connect($dbh,$dbu,$dbp) or die("Unable to connect do database.");
mysql_select_db($dbn, $conn) or die("Unable to select database.");

$result = mysql_query("SHOW TABLES FROM $dbn") or die("Cannot list table names.");
echo "
<form name=\"table_browser\" action=\"".$PHP_SELF."\" method=\"GET\" >
<select name=\"t\" onChange=\"javascript:submit();\">
<option>Select a table</option>
while ($row = mysql_fetch_row($result)){
echo " <option value=".$row[0].">".$row[0]."</option>\n";
echo " </select>

if (!isset($t)){
die("Please select a table");


You need to use full php code here