Assign the value of an input to a php variable

Asked

Viewed 109 times

-1

Guys, I have this code and I need to assign the value of select to a php variable. How do I do that?

<form name="form-avaliacao" method="post" action="confirmacao-avaliacao.php">
                    <label>Disciplina *</label><br>
                    <select name="disciplina" id="disciplina" required>
                    <option>Selecione uma disciplina</option> 
                    <option>Artes</option>  
                    <option>Biologia</option> 
                    <option>Educação Física</option> 
                    <option>Filosofia</option>  
                    <option>Física</option> 
                    <option>Geografia</option>
                    <option>História</option> 
                    <option>Inglês</option>
                    <option>Matemática</option>
                    <option>Português</option> 
                    <option>Química</option> 
                    <option>Sociologia</option>
                    </select> <br><br>
  • You have to send the select value to the server and do the assignment in PHP. The problem is that the question is too shallow for information.

  • The idea is this: Once the user selects one of the select options, the selected option must be saved in a variable. Then I make an if with this variable, to store its value in the bank.

  • Example: just below this select would have this: <? php $select = the value of the top select if($select == "Math") { $category = $select; INSERT INTO tb_ratings (category) VALUES = '$category'; }

  • Important [Dit] and post what you tried, and an explanation of what did not work. Tutorials, tips and guesses are not part of the site profile

1 answer

0


As the form makes a post, you can pick up the value in confirmacao-avaliacao.php with $_POST["NOME_DO_CAMPO"]. The name is identified by name in HTML. In your case, it would then $_POST["disciplina"].

For more details, you can consult https://www.w3schools.com/php/php_forms.asp

  • Wow, I didn’t think of that, maybe it’ll work. Thank you!

  • Just supplemented what @tvdias said above. You have not posted all the html code of your form, it is necessary that you have a button of type Submit within this form.

Browser other questions tagged

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