【发布时间】:2020-08-24 15:02:02
【问题描述】:
这是一个由两部分组成的问题 - 抱歉!
我看到第一部分有很多答案,即 I.E.如何在表单中填充下拉列表。
第 1 部分 但是,当我将表单(带有 DDL)放在表中时,一切都会出错并且不起作用。
问题 1 为什么没有填充 DDL? - 表中有 4 个名称,每个名称都有其他列 - ID、名称、昵称等。
第 2 部分 我想返回所选“名称”的“ID”,然后将其添加到另一个表中,其中包含其他数据。目前,“ID”没有传递给正在写入文件的 PHP。
问题 2 我需要在我的代码中添加什么来返回所选名称的 ID? IE。我不想要表格中的名称,只需要名称的 ID。
代码在这里:
<!doctype html>
<html>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "dbname";
// Create connection
$conn = mysqli_connect( $servername, $username, $password, $dbname );
// Check connection
if ( $conn->connect_error ) {
die( "Connection failed: " . $conn->connect_error );
}
?>
<body>
<form method="post" action="property.php">
<table>
<tr>
<td>Property Name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Agent Name:</td>
<td>
<select>
<?php
$res = mysqli_query( $conn, "select * from Names" );
while ( $row = mysqli_fetch_array( $res ) ) {
?>
<option value="id">
<?php echo $row["name"] ?>
</option>
<?php
}
?>
</select>
</td>
</tr>
</table>
</body>
</html>
任何帮助都会很棒!
干杯!!
【问题讨论】:
标签: php mysql database forms html-table