Fetch field name and Insert into

Asked

Viewed 26 times

1

Good, I wonder if someone could give me a little help?

I am trying to make a dynamic Insert, where the user chooses in a select box in which table will insert the data. But I would like that when it selects the table, appear the respective fied.

I leave here the code I have:

<html>
<head>
<title>Products</title>
</head>
<body>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}

li {
float: left;
}

li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}

li a:hover, .dropdown:hover .dropbtn {
background-color: orange;
}

li.dropdown {
display: inline-block;
}

.dropdown-content {
display: none;
position: absolute;
background-color: #000000;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}

.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}

.dropdown-content a:hover {background-color: #000000}

.dropdown:hover .dropdown-content {
display: block;
}
</style>
</head>
<body>

<ul>
<li><a href="welcome.php">Home</a></li>
<li><a href="">Info</a></li>
<li><a href="">Info</a></li>
<li><a href="welcome.php">Voltar</a></li>

</ul>
</body>
</html>
<br>
<br>
<?php
$mydbname = 'visteon';
$conn=mysqli_connect('127.0.0.1','root','','visteon');

if(mysqli_connect_error($conn))
{
echo 'Failed to connect';
}


$options = '';

$result = mysqli_query($conn,"SHOW TABLES");
$column_name ='Tables_in_'.$mydbname;

while($row = mysqli_fetch_array($result))
$options .= '<option value="' . $row[$column_name] . '">' . 
$row[$column_name] . '</option>';


echo '<select name="users" onchange="showTables(this.value)">';
echo '<option value="0">Select a table:</option>';
echo  $options;
echo '</select>';

?>
<br>
<form method="post" action="processprodutos.php">
<label>Tipo</label>
<input type="text" name="Tipo">
<br>
<label>Quantidade</label>
<input type="text" name="Quantidade">
<br>
<label>Linha</label>
<input type="text" name="Linha">
<br>
<input type="submit" value="Adicionar">
</form>
</body>
</html> 

I await reply,

Hug.

1 answer

0

To get the columns of a given table in Mysql just do the following:

SHOW COLUMNS FROM tabela;

The properties that may interest you will be:

Field (column name)
Type (type of data in the column)

Then you just have to build a grid to show them.

  • I really wanted something like this: A select box with which the user can interact so that he chooses which table he wants to enter the data, when selecting the table the fields/field name’s updated (changed) according to the chosen table. Is this possible? If yes I needed help. Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.