0

The values from the db are displaying in the dropdown and I've gotten it to work with text values that weren't pulled from the db, but when I try it with values from the db and click 'Submit' the page reloads and nothing happens.

My code:

<form action="test.php" method="post">
<br />
<label for="name">Choose a name</label><br />

 <select name="selected_value">
 $query = "SELECT * FROM items WHERE user_id = $user_id";
 $select_items = mysqli_query($connection, $query);
 confirmQuery($select_items);
 while($row = mysqli_fetch_assoc($select_items)) {
 $item_id = $row['item_id'];
 $item_name = $row['item_name'];
 echo "<option value='$item_name'>{$item_name}</option>";

 </select>
 <button type="submit" name="submit_form">Submit</button>
 </form>


 if(isset($_POST['submit_form'])){
 $selected_value = $_POST['selected_value'];
 echo $selected_value;
 }

1 Answer 1

1

Don't you have this the wrong way around?

$_POST['selected_value'] = $selected_value;

should be

$selected_value = $_POST['selected_value'];

Sign up to request clarification or add additional context in comments.

2 Comments

Yes; that was wrong and has been updated. But the problem still exists after rearranging this
Alright, try this: echo "<option value='$item_name'>{$item_name}</option>"; should be echo "<option value='$item_name'>" . $item_name . "</option>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.