user21243 user21243 - 5 months ago 7
MySQL Question

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

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


connection

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


getting data from the data base

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

if(mysqli_num_rows($sql)){

$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
$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
 }
 $select.='</select>';

addtosql.php

<?php
//Connect to db
$id= $_GET['id'];
// Insert $id into db
?>