我在php中有一个脚本可以提取下拉列表的信息。当我点击帖子时,我希望从下拉列表中选择的内容在另一个名为techissuses
的表中发布。
<form action="insert.php" method="post">
<?php mysql_connect("localhost", "root", "") or die("Connection Failed");
mysql_select_db("mysqli")or die("Connection Failed");
$query = "SELECT * FROM manufactures"; $result = MySQL_query($query); ?> <select name="select1">
<?php while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
< <option value="<?php echo $line['name'];?>">
<?php echo $line['name'];?>
</option> <?php } ?> </select>
First name: <input type="text" name="firstname">
Last name: <input type="text" name="lastname">
Age: <input type="text" name="age">
<input type="submit">
</form>
这是insert.php
将写入Techissues
输入代码:
// escape variables for security
$firstname = mysqli_real_escape_string($con, $_POST['firstname']);
$lastname = mysqli_real_escape_string($con, $_POST['lastname']);
$age = mysqli_real_escape_string($con, $_POST['age']);
$Techissues = mysqli_real_escape_string($con, $_POST['techissues']);
$sql="INSERT INTO Persons (FirstName, LastName, Age, Techissues)
VALUES ('$firstname', '$lastname', '$age', '$techissues')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>