我试图让一个下拉列表显示来自表单上的mysql数据库的数据以添加记录。我找不到让它工作的方法,它没有显示任何东西,所以我甚至无法尝试。我正在学习php和mysql,所以我不知道代码中有什么问题,虽然连接很好。建议?在此先感谢,这是代码。
<?php
include("includes/connect.php");
doDB();
if (!$_POST) {
$display_block = "
<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
<div class=\"form-group\">
<div class=\"row\">
<div class=\"col-md-8\">
<label>Dominio</label>
<input class=\"form-control input-sm\" name=\"dominio\" type=\"text\" placeholder=\"dominio\">
</div>
</div>
</div>";
//get plan list
$get_planlist_sql = "SELECT * FROM PLANES ORDER BY plan ASC";
$get_planlist_res = mysqli_query($mysqli, $get_planlist_sql)
or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_planlist_res) > 0) {
$display_block .="<div class=\"form-group\">
<div class=\"row\">
<div class=\"col-md-8\">
<label>Plan</label>
<select class=\"form-control input-sm\">
<option value=\"\>Selecciona</option>";
while ($getplans = mysqli_fetch_array($get_planlist_res)) {
$plan = $getplans{'plan'];
$display_block .= "<option value=\"".$plan"\">".$plan."</option>";
}
$display_block .= "
</select>
<div class=\"form-actions\">
<button type=\"submit\" class=\"btn btn-primary btn-lg\">Ingresar usuario</button>
</div>
</form>";
}
//free result
mysqli_free_result($get_planlist_res);
} else if ($_POST) {
//Revisar los campos requeridos
if (($_POST["dominio"] == "") || ($_POST["plan"] == "")) {
header("Location: cliente.php");
exit;
}
//Add to table datos_cliente
$add_datosclientes_sql = "INSERT INTO datos_cliente (dominio, plan) VALUES ('".$_POST["dominio"]."', '".$_POST["plan"]."')";
$add_datosclientes_res = mysqli_query($mysqli, $add_datosclientes_sql)
or die(mysqli_error($mysqli));
mysqli_close($mysqli);
$display_block = "<p>La incidencia ha sido enviada. Deseas <a href=\"nuevo-cliente.php\">agregar otra</a>?</p>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/bootstrap.css" />
<title>Untitled Document</title>
</head>
<body>
<div class="container">
<div class="row">
<?php echo $display_block; ?>
</div>
</div><!--end container-->
</body>
</html>