user21243 user21243 - 1 year ago 57
MySQL Question

How to post the result of this dropdown into an sql table?

$dbc = mysqli_connect("localhost","root","","bce_db");


$query = "SELECT assignee_code,assignee_name FROM assignees";

getting data from the data base

$sql = mysqli_query($dbc,$query);


$select = '<select name = "select">';//dropdown created

while($rs = mysqli_fetch_array($sql)){

$select.='<option value = "'.$rs['assignee_code'].'">'.$rs['assignee_code'].'</option>';
$select.='</select>';//dropdown ended..

//I used the $POST method by linking it to other php page, but it returns undefined variable
echo $select;

How to post the value of the dropdown in table?

Answer Source
$select = '<select name = "select" onchange="location = this.value;">';
while($rs = mysqli_fetch_array($sql)){

  $select.='<option value = "addtosql.php?id='.$rs['assignee_code'].'">'.$rs['assignee_code'].'</option>'; //you can change the filename addtosql into whatever you want


//Connect to db
$id= $_GET['id'];
// Insert $id into db
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download