douqujin2767
douqujin2767
2013-08-02 18:31
浏览 77
已采纳

从下拉框中获取MYSQL值

So I have some php code to return a mysql table to a dropdown box, as follows:

$hostname = ""; //SET SERVER/HOSTNAME
$dbusername = ""; //SET DATABASE USERNAME
$dbname = ""; //SET DATABASE NAME
$dbpassword = ""; //SET DATABASE USERNAME
$link = mysqli_connect($hostname, $dbusername, $dbpassword, $dbname); 

if (!$link)
{ 
    die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); 
} 

$sql = "SELECT * FROM utility ORDER BY program_code"; 

if ($result = mysqli_query($link, $sql)) 
{    
    while ($row = mysqli_fetch_assoc($result)) 
    {
        $selectbox.='<option value=\"' . $row['program_code'] . '\">' 
        . $row['program_code'] . ' - ' . $row['rate'] . ' - ' . $row['term'] . '</option>';
    }

    $selectbox.='</select>';

    mysqli_free_result($result);

    echo $selectbox;
}

That works fine, then I just call that into my form. My problem is when an option is selected, I need to get and return that value so I can pass it on to whatever else I am doing with the values from my form. Any help is greatly appreciated. Thank you.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongxun1142
    dongxun1142 2013-08-02 18:48
    已采纳
    <select name="select">
      <option value="foo">foo</option>
    </select>
    

    PHP:

    $select = $_POST["select"];
    echo $select; //Should return foo
    
    点赞 评论

相关推荐