我尝试使用 php 代码填充组合框,但无法正确执行/显示 登录屏幕的代码,它从分支表中选择记录并放入组合按钮以供用户选择,但它没有正确显示,请检查
<!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" />
<title>Visual Securas Login Page</title>
</head>
<body>
<div class="wrapper">
<div class="container">
<h1>Welcome To Visuak Securas</h1>
<?php
$servername = "localhost";
$username = "root";
$password = "xxxxx";
$dbname = "visual";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
<form class="form">
<?php
$sql = "SELECT branchname FROM branch";
$result = $conn->query($sql);
echo "<select name=\"pcid\">";
echo "<option size =30 ></option>";
while($row = $result->fetch_assoc())
{
echo '<option value="'.$row['branchname'].'">'.$row['branchname'].'</option>';
}
echo "</select>";
?>
<input type="text" placeholder="Username">
<input type="password" placeholder="Password">
<select multiple="multiple"
<button type="submit" id="login-button">Login</button>
</form>
</body>
</html>
最佳答案
根据当前的情况,我认为这是一个样式问题,似乎没有样式应用于您的选择标记。 (CSS) 否则,它会准确地显示在代码中的位置。
编辑:
Chunk1:CSS 非常小,放在头部而不是链接
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>My first styled page</title>
<style type="text/css">
body {
color: purple;
background-color: #d8da3d }
</style>
</head>
<body>
[etc.] (not shown)
与接下来的 2 个 block 组合(即, block 2 和 block 3 有点结婚)
Chunk2:外部CSS文件
这是首选方式,CSS 是可重用的。 假设这是一个名为 myStyle.css 的 css 文件
body {
padding-left: 11em;
font-family: Georgia, "Times New Roman",
Times, serif;
color: purple;
background-color: #d8da3d }
ul.navbar {
list-style-type: none;
padding: 0;
margin: 0;
position: absolute;
top: 2em;
left: 1em;
width: 9em }
h1 {
font-family: Helvetica, Geneva, Arial,
SunSans-Regular, sans-serif }
ul.navbar li {
background: white;
margin: 0.5em 0;
padding: 0.3em;
border-right: 1em solid black }
ul.navbar a {
text-decoration: none }
a:link {
color: blue }
a:visited {
color: purple }
address {
margin-top: 1em;
padding-top: 1em;
border-top: thin dotted }
Chunk3:包含我们刚刚在Chunk2中看到的myStyle.css
在 <body>
中适当使用 css 样式
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>My first styled page</title>
<link rel="stylesheet" href="myStyle.css">
</head>
<body>
[etc.] (not shown)
好的, block 结束了。您基本上需要通过 PHP 呈现文本来执行此操作,但您并没有这样做。再次注意,您要么执行 Chunk1,要么执行(Chunk2 和 Chunk3)。所以你的问题是样式/html/css问题。
关于使用 Mysql 的 PHP 组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31842129/