PHP and SQL dropdown?

Hey guys i was wondering if you could help me with an issue. I know how to post text fields, usernames and passwords.But I want to have a dropdown that gets tables from my database and i want to select the table and then post to the database which table is assigned to the ftp I’m using. This script is for adding FTP details to MySQL database so each user can get their own CSV files. This is what i have so far:

	<label>Folder Structure :</label>
	<input type="text" name="location" id="location" required="required" placeholder="folder1/folder2"/><br /><br />
<label>Host Name :</label>
<input type="text" name="hostname" id="hostname" required="required" placeholder=""/><br /><br />
<label>Username :</label>
<input type="text" name="username" id="username" required="required" placeholder="John123"/><br/><br />
<label>Password :</label>
<input type="text" name="password" id="password" required="required" placeholder="Password"/><br/><br />
<label>CSV Filename :</label>
<input type="text" name="filename" id="filename" required="required" placeholder="test.csv"/><br/><br />
<label>RTU :</label>

$result = $con->query("SHOW TABLES WHERE `Tables_in_irrigation` NOT LIKE 'user%' and `Tables_in_irrigation` NOT LIKE 'company%' and `Tables_in_irrigation` NOT LIKE 'roles%' and `Tables_in_irrigation` NOT LIKE 'ftp%'and `Tables_in_irrigation` NOT LIKE 'RTU_LINK%'");

if($result->num_rows > 0) {
    echo '<select name="rtu" id="rtu">';
    while($row = $result->fetch_array(MYSQLI_NUM)) {
        echo '<option>' . $row[0] . '</option>';

    echo '</select>';


$sql = "INSERT INTO ftp (location,hostname,username,password,filename,rtu)
VALUES ('".$_POST["location"]."','".$_POST["hostname"]."','".$_POST["username"]."','".$_POST["filename"]."','".$_POST["rtu"]."')";

if ($conn->query($sql) === TRUE) {
echo "<script type= 'text/javascript'>alert('New record created successfully');</script>";
} else {
echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";


So what happens when you run the code? Is there a problem with the list of tables in the drop-down, or a problem when you store the information in your new table, or something else? There’s a significant issue in your insert query, is that where you’re having trouble?

Presumably you’re doing some kind of validation and sanitising of the form data before you insert it into the new table, too? Or plan to add it once it’s all working.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.