Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将MySQL中的条目放入选项列表_Php_Html_Mysql_Select_Options - Fatal编程技术网

Php 如何将MySQL中的条目放入选项列表

Php 如何将MySQL中的条目放入选项列表,php,html,mysql,select,options,Php,Html,Mysql,Select,Options,目前我正在开发一个基于网络的库存软件。对于外出预订,我需要一份带有硬件的动态房间列表。 我在表'ort'中有这个列表,该列也被命名为'ort'。 我希望表格中的条目显示在选项列表中 <select> <option>Content out of database</option> </select> 数据库外的内容 为此,我目前有以下代码: <!DOCTYPE html> <html lang="de"> &l

目前我正在开发一个基于网络的库存软件。对于外出预订,我需要一份带有硬件的动态房间列表。 我在表'ort'中有这个列表,该列也被命名为'ort'。 我希望表格中的条目显示在选项列表中

<select>
<option>Content out of database</option>
</select>

数据库外的内容
为此,我目前有以下代码:

    <!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <title>Ausbuchung</title>
    <meta name="Author" content="Microgamer"/>
</head>
<body>

    <form action="auth.php" method="post">
    Seriennummer:<input type="text" name="Seriennummer"><br>


<?php

$db=mysql_connect("localhost", "dvd","abc");
mysql_select_db("inventar");
$anfrage="SELECT ort FROM ort ";
$ergebnis=mysql_query($anfrage);
?>


<select> 
<?php 

    $sql = "SELECT 
                ort 
            FROM 
                ort"; 
    $result = mysql_query($sql) OR die(mysql_error()); 
        while($row = mysql_fetch_assoc($result)) { 
echo "<option>" . $row['ort'] . "</option>"; 
} 
?> 
</select>

    <input type="text" name="pc"><p>PC-Name</p>
    </form>

</body>
</html>

奥斯布孔
序列摘要:
电脑名

现在打开页面时,我看到以下内容:

你能帮帮我吗?我没有更多的想法

谢谢 Microgamer使用如下选择框:

<select name="selectbox_name">
<?php
  foreach(mysql_fetch_assoc($result) as $sql)) {
   echo '<option value="' . $sql['row'] . '">' . $sql['row'] . '</option>';
}
 ?>
</select>


您是否检查了查询是否给出了正确的结果?似乎没有查询结果。另外,
mysql
已弃用,请改用
mysqli
。mysql扩展已弃用,将来将被删除:请使用mysqli或PDO代替
echo($result)?确定查询不会给出任何结果…如果没有结果也无所谓,即使没有给出任何值,它仍会显示在OP代码的选择框中。最初没有打印
。但现在我遇到了这个错误:
致命错误:无法在
中的写入上下文中使用函数返回值,行如下:
foreach($sql as mysql\u fetch\u assoc($result)){
@SpencerWieczorek那么我认为数据库一定有错误。我会拍照并将它们发送到这里。希望这会有助于尝试:$sql=“SELECT*FROM ort”;$query=mysql\u query($sql);var\u dump($query);