Data-Base Managemente Aplication

Hey, im trying to do an insert in my app, but i need to create something to the user choose where he wants(table) to insert the data. To do that i’ve made a select box to select the table, but now i want to show the fields and insert the data into the selected one.
Help me please, i know its hard to understand but its urgent!
Thanks.

<html>
     <head>
     <title>Products</title>
     </head>
     <body>
     <html>
     <head>
     <style>
      ul {
</style>
</head>
<body>
</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>

So you made assuptions about what your software should do - where’s the actual problem with this? At least you don’t perform any insert. There’s even any choosable content missing because there’s no form the user can interact with.

“form:”

<br>
<br>
<form method="post" action="databaseprodutos.php">
<pre><label></label>
<input type="text" name="">
<br>
<pre><label></label>
<input type="text" name="">
<br>
<pre><label></label>
<input type="text" name="">
<br>
<input type="submit" value="Submit"> 
</form>
</body>
</html>

The select is outside of this form. And you ignored everything else from my post.

1 Like

the main problem is i don’t know how to do it

that’s just RTFM:

https://www.php.net/manual/en/tutorial.forms.php

https://dev.mysql.com/doc/refman/8.0/en/insert.html

i understand your point of view mate, but i have to use the select box and it has to be dynamic, i cant put in the source where to insert or what to insert, the only thing i will have its the fieldnames, data types and the name of the table

So whats the problem? Use the select box within the form.

If you’re in a hurry and the client is supposed to be able to insert anything into any table then is it ok to just give them adminer or phpmyadmin?

i still have 2months to finish, but im stuck in this almost for 2 weeks, and i cant discover how to do it

One problem I often see newer developers have is that they take on this rather large task and poke at it for some time before declaring “i don’t know how to do it”.

I usually ask what it is exactly they don’t know what to do? If you break up the task into smaller more managable pieces, then you’ll often find you’re more than capable of figuring out how it’s done.

So to help out this time - quickly reading over this I’d say you need at least this

selectTable.php

fetch the tables the user is allowed to insert into
show a list, drop down or otherwise of the tables in the database
get the selection to the next page

insertInto.php?table=some_table

verify that the user is actually allowed to edit this table (to prevent ie someone inserting a new root user in mysql.user)

ON SUBMIT:

  • validate the data
  • insert data into the database
  • optionally: redirect back to the selectTable.php

use the get variable “table” to fetch the columns of the table
create a form
iterate over the columns fetched from the table and conditionally show a text field, numeric field, text box, etc depending on column type
submit to the same file


If there’s any part of this that you struggle with then get back to us. It’s much easier to help if the scope of the issue is smaller than “i don’t know how to make my app” ^^

Note: if you’re comfortable using some js/ajax you can make this form a lot smoother by automagically fetching and showing the columns for the table on drop down change. Didn’t want to add unnecessary stuff though if it complicates things.

1 Like

This indicates a problem with design. What table data goes into is not dynamic, and if it is, it means the design is not something to continue building against.

So, two months, that is quite a while in the scope of things. What does the application need to do? Stop jumping to the end, you are only going to cause more of a headache than necessary.

It needs to insert, update, delete, and create dynamic tables(done)

If youre talking about crud for db tables (and not the data inside them) then jjst use adminer, phpmyadmin or similar. no need to reinvent the wheel

While this states what you are trying to do, you haven’t stated the reason/context of why you are doing this.

If you are doing this as a general purpose assignment to show you can solve a programming problem, JimL’s reply #11 gives an outline of how you can accomplish this.

If on the other hand, you are doing this because you have actual data that you think needs to be stored in separate tables, such as different categories of products, this is the wrong way of doing this. For this type of ‘dynamic’ data, you would have a category table, that you insert a new row into for each new category, and a single product table that holds all the product information, with a category_id column to identify which category the product belongs to.

So, which of these reasons, or perhaps you have another one, is why you are doing this?

I’m doing this because its my project to finish the 12th Grade in a professional course, and the company wheres im doing my internship suggested me this project

And that’s fine that they suggested it. What we are saying is, your thought process on the How is incorrect.

CRUD systems are easy, but in no way do they need the type of dynamic nature that you are inferring.

Sponsor our Newsletter | Privacy Policy | Terms of Service