TerribleCodeMan TerribleCodeMan - 8 months ago 31
HTML Question

HTML/PHP Select refuses to store a value

I am trying to make a dropdown list with values from a database, but when I try testing whether the value was taken in, I get nothing.

<select name = "student_id">
<option value="" >choose student</option>
$getnames = @mysqli_query($dbc, "SELECT student_id, first_name, last_name FROM students");

while ($row = mysqli_fetch_array($getnames))
?><option value = "<?php echo $row['student_id']; ?>">
<?php echo $row['student_id'] . ' ' .$row['first_name'] . ' '. $row['last_name'];
?></option>"; <?php

The list appears to be fine, showing the student id, first name and the last name of all entries in the database, but when I test the value taken in with this

$studentid = trim($_POST['student_id']);

echo $studentid;

require_once ('../mysqli_connect.php');

And it does not return anything. Everything seems to work with other lists where I did not use any loops and just typed out each option, but I can't find issues In the loop.

Sorry for the terrible question.

?><option value = "<?php $row['student_id']; ?>">   
                         ^---missing echo

If you'd done any basic debugging, like a view source of your generated html, you'd have seen that all of your option values are empty...

So, not, it's not the option refusing to store a value. it's doing EXACTLY what YOU told it to: send an empty/blank value to the server.