James Pierce
James Pierce

Reputation: 23

PHP-HTML5-Form - My query-generated dropdown posts a blank value

When I load my page, the value of the variable, $v_UpdateONE, is "Select Version". When I select a version, the value goes blank. I need to grab the selected value for use in a DB update statement. Thank you for any assistance. -James

<FORM METHOD="post" ACTION="Update.php" WIDTH="50">
<?php

$avQuery = "SELECT $v_software1 FROM version_master.vermas_availableversions WHERE $v_software1 IS NOT NULL ORDER BY SortCol DESC";
  $a_AvailVers = mysql_query($avQuery);
  #_Version dropdown box
  echo "<select NAME='AvailVersONE' ONCHANGE=submit()>";
  echo "<option>Select Version</option>";
  while ($row = mysql_fetch_array($a_AvailVers)) {
    echo "<option value='" . $row['$v_software1'] . "'>" . $row[$v_software1] . "</option>";
  }
 echo "</select>";

 $v_UpdateONE = $_POST['AvailVersONE'];
 echo $v_UpdateONE;

?>
</FORM>

Upvotes: 2

Views: 53

Answers (2)

Sean
Sean

Reputation: 12433

You have an error in

value='" . $row['$v_software1'] . "'

Since $v_software1 is in single quotes, it will be literal $v_software1.

Try removing the quotes -

value='" . $row[$v_software1] . "'

Upvotes: 1

Vhortex
Vhortex

Reputation: 381

You need to post before you can read $_POST data.

Form File

 <FORM METHOD="post" ACTION="Update.php" WIDTH="50">
<?php

$avQuery = "SELECT $v_software1 FROM version_master.vermas_availableversions WHERE $v_software1 IS NOT NULL ORDER BY SortCol DESC";
  $a_AvailVers = mysql_query($avQuery);
  #_Version dropdown box
  echo "<select NAME='AvailVersONE' id='AvailVersONE' ONCHANGE=submit()>";
  echo "<option>Select Version</option>";
  while ($row = mysql_fetch_array($a_AvailVers)) {
    echo "<option value='" . $row['$v_software1'] . "'>" . $row[$v_software1] . "</option>";
  }
 echo "</select>"; 
?>
<button type="submit"> <!-- this will draw a submit button -->
</FORM>

then on your Update.php

<?php

$v_UpdateONE = $_POST['AvailVersONE'];
echo $v_UpdateONE;

?>

Sometimes, the ID needs to be filled up (browser dependent)

Upvotes: 0

Related Questions