gpt4 book ai didi

mysql - 表单中带有 MySQL 的 HTML 下拉框

转载 作者:行者123 更新时间:2023-11-30 01:35:31 24 4
gpt4 key购买 nike

我有可以运行的 PHP 编码,但我没能将其转换为 HTML 表单。有什么建议吗?

<?php
$db_host = "localhost";
$db_username = "combsb_combsb";
$db_pass = "pat60086";
$db_name = "combsb_sample";

@mysql_connect ("$db_host", "$db_username", "$db_pass") or die ("Could not connect to MySQL");
@mysql_select_db("$db_name") or die ("No Database");

Echo"Successful Connection";


$sql = "SELECT compname FROM Crew";
$result = mysql_query($sql);

echo "<select name='compname'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['compname'] . "'>" . $row['compname'] . "</option>";
}
echo "</select>";


?>

最佳答案

首先,我要确保在 PHP 周围添加 HTML 样板。那么我认为你的意思是 mysql_fetch_row 而不是 mysql_fetch_array 。您的最终文件应类似于:

<!DOCTYPE html>
<html>
<head></head>
<body>
<?php
// *Cut out for brevity, remember to paste back in*
$result = mysql_query($sql);
?>

<form action="" method="POST">

<?php
echo "<select name='compname'>";

while ($row = mysql_fetch_row($result)) {
echo "<option value='" . $row['compname'] . "'>" . $row['compname'] . "</option>";
}

echo "</select>";
?>

</form>
</body>
</html>

下次发布您的输出/错误或者如果这不起作用

关于mysql - 表单中带有 MySQL 的 HTML 下拉框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16947083/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com