Reputation: 45
Since i couldn't find anything that solved my problem, i thought i should ask it here.
I have 2 dropdowns with a submit button, the values save in my database.
The problem is that when i refresh my page, the dropdown value goes back to the first value, so the dropdown values doesn't change to the database value.
Example:
PHP Table: https://i.gyazo.com/b5eb036d8cb9407132ff39b67434ed65.png
Database: https://i.gyazo.com/fab5eca498dc566383de092c687f7f01.png
PHP Code:
<form action="submit_stdntdetails.php" method="post">
<select name="potentieel" id="potentieel">
<option value="volvo">Volvo XC90</option>
<option value="saab">Saab 95</option>
<option value="mercedes">Mercedes SLK</option>
<option<?php if ($potentieel == "Loaned"): ?>
selected="selected"<?php endif; ?
>>Loaned</option>
</select>
<?"</td>";
echo "<td>"?>
<select name="prestatie">
<option value="volvo">Volvo XC90</option>
<option value="saab">Saab 95</option>
<option value="mercedes">Mercedes SLK</option>
<option value="audi">Audi TT</option>
</select>
<input type="submit" value="Submit" style="
border-top-width: 1px;
border-bottom-width: 1px;">
</form>
<?"</td>";
submit_stdntdetails.php:
if(isset($_POST['potentieel'])){
$potentieel=$_POST['potentieel'];
}
if(isset($_POST['prestatie'])){
$prestatie=$_POST['prestatie'];
}
$sql = "UPDATE employees
SET potentieel = '$potentieel', prestatie = '$prestatie'
WHERE ID = 1";
As you can see i changed the last option to try if that worked, but it doesn't Hope someone could help me, thanks
Upvotes: 0
Views: 102
Reputation: 23
Use $_SESSION variables to set the select default. When the form is submitted, set your $_SESSION['yourVarName'] equal to the $_GET or $_POST data. This is how I have done this in the past.
http://php.net/manual/en/function.session-start.php
Upvotes: 1