Note that there are some explanatory texts on larger screens.

plurals
  1. POerror in my PHP code drop down list to select item from MYSQL
    primarykey
    data
    text
    <p>i have interface which have drop down list, you have to select an item and click on submit button to view the database in mysql but doesn't work, it give error "Table 'balhaf.$table' doesn't exist"</p> <p>here is my code the interface</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;form method="post" action="list_files.php"&gt; &lt;input name="go" type="submit" value="submit" / &gt; &lt;?php $dbname = 'balhaf'; if (!mysql_connect('localhost', 'sqldata', 'sqldata')) { echo 'Could not connect to mysql'; exit; } $sql = "SHOW TABLES FROM $dbname"; $result = mysql_query($sql); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } echo '&lt;select name="dropdown" style="width:150px"&gt;'; echo '&lt;option value=""&gt;Select&lt;/option&gt;'; while ($row = mysql_fetch_row($result)) { echo '&lt;option value="'.$row[0].'"&gt;'.$row[0].'&lt;/option&gt;'; } echo '&lt;/select&gt;'; echo '&lt;/form&gt;'; mysql_free_result($result); ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>my second code "list_files.php"</p> <pre><code>&lt;?php if(isset($_POST["dropdown"])) { echo "ok"; } $table = $_POST['dropdown']; // Connect to the database $dbLink = new mysqli('localhost', 'sqldata', 'sqldata', 'balhaf'); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } // Query for a list of all existing files $sql = 'SELECT `id`, `name`, `mime`, `size`, `created` FROM $table'; $result = $dbLink-&gt;query($sql); // Check if it was successfull if($result) { // Make sure there are some files in there if($result-&gt;num_rows == 0) { echo '&lt;p&gt;There are no files in the database&lt;/p&gt;'; } else { // Print the top of a table echo '&lt;table border="1" align="center"&gt; &lt;H2 align="center"&gt; Report Table&lt;/H&gt; &lt;tr&gt; &lt;td&gt;&lt;b&gt;Name&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b&gt;Mime&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b&gt;Size (bytes)&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b&gt;Created&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b&gt;Download&lt;/b&gt;&lt;/td&gt; &lt;/tr&gt;'; // Print each file while($row = $result-&gt;fetch_assoc()) { echo " &lt;tr&gt; &lt;td&gt;{$row['name']}&lt;/td&gt; &lt;td&gt;{$row['mime']}&lt;/td&gt; &lt;td&gt;{$row['size']}&lt;/td&gt; &lt;td&gt;{$row['created']}&lt;/td&gt; &lt;td&gt;&lt;a style='text-decoration:none;' href='get_file.php?id= {$row['id']}'&gt;Download&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt;"; } // Close table echo '&lt;/table&gt;'; } // Free the result $result-&gt;free(); } else { echo 'Error! SQL query failed:'; echo "&lt;pre&gt;{$dbLink-&gt;error}&lt;/pre&gt;"; } // Close the mysql connection $dbLink-&gt;close(); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload