Hi,
I'm having a problem with a sticky form i'm creating. the code is
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<p>Vegetable<select name="vegetable"> //start of veg drop down
<?php
$query="SELECT vegetable_pk, vegetable_type FROM vegetables"; //query db
$result=mysqli_query($dbc, $query) or die("Query failed: " . mysqli_error($dbc)); //run query
while($row=mysqli_fetch_assoc($result)){ //loop thu results
if(isset($_POST['vegetable'])) {
echo '<option value="' . $_POST['vegetable'] . '" selected="selected">' . $_POST['vegetable'] . '</option>';
} else {echo "<option value=\"$row[vegetable_pk]\">$row[vegetable_type]</option>\n"; //echo out results
}
}
This sort of does the job, except that the value that is kept sticky and show to the user is vegetable_pk (the number), rather than vegetable_type (the name).
This makes sense since that is the value stored in $_POST['vegetable'], but how can I make it so that the corresponding name of the selection gets shown in the select? Any help would be great 🙂