This question already has an answer here:
I have the code:
echo('
<div class="row">
<div class="col-sm-2" >
<form method="POST" action="plan.php">
<p>Selectati data raportului:<br>
<select name="SelectDR" onchange="form.submit()">
<option value="">Select...</option>
');
It is a form from which I select a value.
$option = isset($_POST['SelectDR']) ? $_POST['SelectDR'] : false;
if ($option){
$queryTXT = "SELECT * FROM ".$tabel." WHERE DataRaport='".$option."'";
...
The records of a SQLtable are filtered by the value selected from the form.
Now, what I want is to display in the url plan.php?DataRaport& variable php
I've tried to put in the form url (<form method="POST" action="plan.php?DataRaport'.$option.'">
), but that doesn't show the variable.
</div>
You need GET not POST
<form method="GET">
First of all. If you want to echo this HTML every time, just use it as HTML:
<div class="row">
<div class="col-sm-2" >
<form method="POST" action="plan.php">
<p>Selectati data raportului:<br>
<select name="SelectDR" onchange="form.submit()">
<option value="">Select...</option>
</select>
</form>
<?php //your php stuff
To get the value from the URL, you need to change one thing:
<form method="POST" action="plan.php?DataReport=<?php echo $option?>">
Then you would get this variable as:
$dataReport = $_GET['DataReport'];
This would return the option value as POST
and the DataReport
as GET
.
You can change the form method to GET
if you wish, but you would then need to use $_GET
to pick the selected option.