Hi. This is more of a concept question than anything else.
A user logs into MySQL with pre-set details, minus the database. The inital load gives them a drop down box of all the current available databases they can select. They pick one, then it loads the associated tables for that database.
The problem is, once you select a table to view, the code forgets the database the was selected. I think this is because of the load request not specifiying the database again, so it resets the connection and thus can't load the table because there is no database selected anymore.
Am I supposed to use cookies at this point?(don't know anything about them just yet, but this is what I assume keeps current connections temporary connected during multiple loads?) Or is it my code? I mean it's sloppy and outdated atm, but I assume the basic concept is on track?
Anyhow if anyone has any opinions I'd love the hear. Thanks for reading.
<?php
//request login details from file
require_once 'login.php';
$db_database = 'test';
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("unable to connect to the server");
echo <<<_END
Command 1, access server location, user and pass. Requires password/selection access to be added
<h1><b>Command has been granted</b></h1>
<h5>Primary Commands
<select name="" form="">
<option value="">"mysql_connect(Server, User, Pass)"</option>
<option value="">"mysql_select_db(Name, server)"</option>
<option value="">"mysql_query(Mysql Command lines)"</option>
<option value="">"mysql_num_rows(Result from query?)"</option>
<option value="">"mysql_fetch_row(Result from query?)"</option>
</select>
</h5>
<br>
<h5>Access MySQL Database</h5>
Comman 2, Show databases<br>
<h5>Select Database</h5>
_END;
$db_display = "SHOW DATABASES;";
$db_result = mysql_query($db_display); // ID return from SHOW DATABSES;
if(!$db_result) die("Unable to show databases");
$db_amount = mysql_num_rows($db_result); // number of databases;
echo "<Form action='rebuilt.php' method='post' >
<select name='db_selected'>";
for($j = 0; $j <= $db_result; $j++)
{
$row = mysql_fetch_row($db_result);
echo "<option value='$row[0]'>$row[0]</option>";
}
echo "</select>
<input type='submit' value='Select Database' />
</form>";
$db_selection = $_POST['db_selected'];
$db_select = "USE $db_selection;";
$db_selected = mysql_query($db_select);
echo "Using: $db_selection";
$t_showall = "SHOW TABLES;";
$t_query = mysql_query($t_showall);
$t_results = mysql_num_rows($t_query);
echo "<form action='rebuilt.php' method='post'>
<select name='tableselect'>";
for ($j = 0; $j <= $t_results; $j++)
{
$row = mysql_fetch_row($t_query);
echo "<option value='$row[0]'>$row[0]</option>";
}
echo "</select>
<input type='submit' value='Select Table' />
</form>";
$t_display = $_POST['tableselect'];
echo $t_display;
$t_table_select = "USE $t_display;";
$t_selected_query = mysql_query($t_table_select);
echo $t_selected_query;
$t_selected_results = mysql_num_rows($t_selected_query);
echo $t_selected_results;
for($j = 0; $j <= $t_selected_results; $j++)
{
$row = mysql_fetch_row($t_selected_query);
echo "<p>$row[0]</p>";
}
mysql_close($db_server);
?>