我正在将数据填充到装配表中的下拉列表中(表中的值是用户自己使用 php 添加的)。现在我想在零件表中添加 Assembly_Name。想要从此下拉菜单中选择值并需要插入到零件表的 Assembly_Name 列中。我无法选择下拉值并将其插入到零件表中。
部分.php
<html>
<body>
<form action="insert_part.php" method="post">
<!--Assembly_Id: <input type="text" name="Assembly_Id">-->
<?PHP
// Connect to your database ** EDIT THIS **
mysql_connect("localhost","root","abc"); // (host, username, password)
// Specify database ** EDIT THIS **
mysql_select_db("test") or die("Unable to select database"); //select db
$result = mysql_query("select assembly_id,assembly_name from assembly ORDER BY Assembly_Id");
echo '<select name="assembly_name"><OPTION>';
echo "Select an option</OPTION>";
while ($row = mysql_fetch_array($result)){
$assembly_name= $row["assembly_name"];
echo "<OPTION value=\"$assembly_name\">$assembly_name</OPTION>";
}
echo '</SELECT>';
?>
Part_name: <input type="text" name="Part_name">
<input type="submit">
</form>
<hr><hr>
<?php
$con = mysql_connect("localhost","abc");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$result = mysql_query("SELECT * FROM Part ORDER BY Part_Id");
echo "<table border='1'>
<tr>
<th>Assembly Name</th>
<th>Part Id</th>
<th>Part Name</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Assembly_Name'] ."</td>";
echo "<td>" . $row['Part_Id'] . "</td>";
echo "<td>" . $row['Part_Name'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
</body>
</html>
insert_part.php
<?php
$con = mysql_connect("localhost","abc");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$assembly_name = isset($_POST['assembly_name'])
$sql="INSERT INTO Part (assembly_name,Part_Id, Part_Name) VALUES ('$_POST[assembly_name]','$_POST[Part_Id]','$_POST[Part_name]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
header("Location:part.php");
exit;
mysql_close($con);
?>
提交值时,我收到以下错误:
解析错误:语法错误,第 10 行 C:\wamp\www\insert_part.php 中的意外 T_VARIABLE