Saving a value from a drop-down list

Here is my situation, I have 2 pages, one for selecting a value and one for editing database-related things related to this value.

Now I do not know (and investigated a fair bit) about how to store the value selected from the drop-down list in a variable from PHP.

Any ideas?

+3
source share
4 answers

Two steps: First html:

<form action='databasethings.php' method=post>
<select name="myvalue">
  <option value="value1">Value 1</option>
  <option value="value2">Value 2</option>
  <option value="value3">Value 3</option>
</select>
<input type=submit>
</form>

Its for sending values ​​in a databasethings.php script. (

Then in databasethings.php:

$myvalue=$_POST['myvalue'];
//do something with myvalue

This will catch the value 1, 2 or 3 from html in $ myvalue in php

+5
source

HTML:

<form action="page.php" method="get">
<select id="drop" name="drop">
  <option value="Volvo">Volvo</option>
  <option value="Saab">Saab</option>
  <option value="Mercedes">Mercedes</option>
  <option value="Audi">Audi</option>
</select>
<input type="submit" value="Submit!">
</form>

page.php:

<?php
echo $_GET['drop'];
?>
+6
source

I assume that you are submitting a form to a page for editing related to the database. On this page use $ _REQUEST ['the_name_of_the_select_box']

    <select name="the_name_of_the_select_box"> 

the selection value will be in

    $_REQUEST['the_name_of_the_select_box'] or  $_POST['the_name_of_the_select_box'] 
0
source

might like

$('element').change(function(){
               $.ajax({
                    url:"savepage",
                    type:"POST",
                    data:({}),
                    dataType:"html", // json // xml
                    async:false,
                    success: function(msg){
                        alert(msg); // get result
                    }
                });
});
0
source

Source: https://habr.com/ru/post/1781981/


All Articles