Make choice via BD table combobox to insert data

Asked

Viewed 350 times

-3

Exemplifying: Choosing in options in which of table of the Database you want insert your information.

<!---
EXE: Banco de Dados
CREATE TABLE tabela_acao, tabela_comedia, tabela_ficcao(
  id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
   nome varchar(20) not null,
   genero varchar(20) not null,
   clasificacao varchar(20) not null,
);
--->

EXE: Tabela que vai inserir conteudo no BD
<form action="" method="">
   <label for="id1">Nome do Filme</label>
   	<input type="text" name="nome" id="id1" required>
   <label for="id2">Genero do Filme</label>
   	<input type="text" name="genero" id="id2" required>
   <label for="id3">Classificação do Filme</label>
  	<input type="text" name="clasificacao" id="id3" required>
   <input type="submit" value="Adicionar">
</form>

EXE: combobox que vai determinar em gual tabela os filmes ira ser colocados
<select>
    <option>tabela_acao</option>
    <option>tabela_comedia</option>
    <option>tabela_ficcao</option>
</select>

  • 1

    In order to help you must post your code or something you tried to do and even your bank structure. not only that but tbm you should ask a more direct question.

  • 1

    From what I understand he wants to mark the combobox and with it make the select in the bank.

  • It’s like this: I registered a film with the comedy genre, so I choose which table I will put! understood? @Jasar Orion

  • Why don’t you separate the categories and record the movies on the same table? type tables movies and vc has a category field that records which category the movie belongs to.

  • @Jasar Orion, why not work out, what I want to do is not that simple, and will only work with the categories in different tables.

  • me explains what you want to do then because in my view there is no difference because mysql is modular enough for you to manipulate the data in the way q want.

  • @pedroandre please do not add SOLVED, in the title, the site works other than forums. you can accept one of the answers by clicking on v the left of them, or if you have found the solution on your own, you can publish your solution. Visit [tour] and see how the site works.

Show 2 more comments

1 answer

1

your insert code in mysql would be this

Cod html

<form action="?acao=grava" method="post">
   <label for="id1">Nome do Filme</label>
    <input type="text" name="nome" id="id1" required>
   <label for="id2">Genero do Filme</label>
    <input type="text" name="genero" id="id2" required>
   <label for="id3">Classificação do Filme</label>
    <input type="text" name="clasificacao" id="id3" required>
   <input type="submit" value="Adicionar">
</form>

EXE: combobox que vai determinar em gual tabela os filmes ira ser colocados
<select name='tabelas'>
    <option value='0'>Ação</option>
    <option value='1'>Comédia</option>
    <option value='2'>Ficção</option>
</select>

php that will stay before or after form

if($_GET['acao']=="grava"){
   $categoria=array('tabela_acao', 'tabela_comedia', 'tabela_ficcao');
   $sql="INSERT INTO ".$categoria[$tabelas]." set nome='".$_POST['nome'].", genero='".$_POST['genero'].", classificacao='".$_POST['classificacao']."";
   mysqli_query($con,sql);
   echo "dados adicionados";
}

That does exactly what you asked for.

  • I will test your code, but I will create the code in Jsfiddle to show you exactly what I intend, ok.

  • look there <a href="https://jsfiddle.net/userHTML/9gcy6xer/#&togetherjs=Rai4rvduuq">Example</a>

  • still not understood why it would need to be different tables.

Browser other questions tagged

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