0
我試圖連接到MySQL並填充數據到Dropdown。這是我的代碼。一些原因下拉列表沒有得到填充。請建議。PHP表單和填充下拉問題
這是代碼。
<html>
<body>
<?php
$mysqli_connection = new mysqli($db_host, $db_username, $db_password, $db_database);
if (isset($_POST['Submit_1'])) {
require 'submit.php';
require 'validate.php';
if ($form_errors = validate_form()) {
show_form($form_errors);
}
else
{
form_submit_1();
}
}
else
{
show_form();
}
function show_form($errors = '')
{
// were there any errors?
if ($errors) {
//show errors
}
?>
<form name="myForm" id="myForm" method="post">
<?php
$sql = "SELECT id, code FROM table1";
$result11 = $mysqli_connection->query($sql);
echo " <select name = \"state1\" id=\"state1\">";
while ($row = $result11->fetch_assoc()) {
echo "<option value = $row[id]>$row[code]</option>";
}
echo "</select>";
?>
</form>
</body>
</html>
<?php
} // End of show_form()
?>
它仍然不起作用。如果我將下拉代碼邏輯移到函數show_form($ errors ='')的上方,它就會起作用。 – nav100 2011-12-16 21:26:19