Teddy Teddy - 1 month ago 6
PHP Question

How to get select value from another php file?

How to get

<select>
value from another php file.
Example :

index.php

$text = $_POST['text']
<select id="text">
<option> text 1</option>
<option> text 2</option>
<option> text 3</option>
</select>


data.php

$sql= "SELECT column FROM table where $text='text 1'"


as you can read above, how to get value from
$text
in
index.php
and use it in
data.php

Answer

I think you only forgot to add value for options itself

<form method="post" action="data.php">    
    <select name="text" id="text">
        <option value="text 1"> text 1</option>
        <option value="text 1"> text 2</option>
        <option value="text 1"> text 3</option>
    </select>
<input type="submit" value="Submit the form"/>
</form>

then add $_GET on your data.php

$text = $_GET['text']
$sql= "SELECT column FROM table where $text='ABCDE'"