Issue
This is the input type I currently have in index.php
:
<fieldset>
<input type="text" placeholder="GSM" name="gsm" required>
</fieldset>
In the saveToDb.php
I have this:
$gsm = $_POST['gsm'];
It all works fine, but I want to change from text input to drop down. I have managed to load values into my drop down like this:
<?php
$filename = 'values.txt';
$eachlines = file($filename, FILE_IGNORE_NEW_LINES);//create an array
echo '<select name="value" id="value">';
foreach($eachlines as $lines){
echo "<option>{$lines}</option>";
}
echo '</select>';
?>
How can I store the values from dropdown to database, insted of of input text?
Solution
You can assign a value on each option:
echo '<select name="name-of-the-field" id="value">';
foreach($eachlines as $lines){
echo "<option value=\"{$lines}\">{$lines}</option>";
}
and the value you will receive is the one of the option
selected (in order to get the value, nothing changes, you still have to use $selected_value = $_POST['name-of-the-field'];
)
Answered By - Alberto Sinigaglia
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.