我有一个问题,显然我能够做一个下拉列表,我可以从MYSQL中检索值,但是,现在我希望它插入一个新查询,下面2个代码包含我如何放置我的下拉列表列表,其他代码将是我插入和提交数据的方式。所以我的问题是如何将下拉列表中的sbranch_name提交到下一页以便我发布它?
<form action="processstaffb.php" method="post">
<table id="t01">
<h2> Add Staff User </h2>
<tr>
<th width="1%">Branch</th>
</tr>
<tr>
<td width="1%">
<?php
session_start();
$mysqli = new mysqli(spf, dbuser, dbpw, db);
$sql="Select sbranch_name from branches";
$result = $mysqli->query($sql);
if ($result->num_rows > 0) {
echo "<select name1='sbranch_name'>";
while($row = $result->fetch_assoc()) {
echo "<option value='" . $row['sbranch_name'] . "'>" . $row['sbranch_name'] . "</option>";
}
echo "</select>";
}
$mysqli->close();
?>
</td>
</tr>
</table>
<br>
<br>
<input type="submit" id="button2" name="submit" value="Add staff" />
<input type="reset" id="button2" value="Clear"/>
</form>
我要发送到下一页的代码,
if (!empty($_POST['sbranch_name']))
{
$sbranch_name =$_POST["sbranch_name"];
}
else
{
$sbranch_name = null;
echo '<p><font color="red">You forgot to enter the branch of the officer!</font></p>';
// testing whether i have managed to bring over.
echo "$name1";
echo "$sbranch_name";
}
if ($sbranch_name)
{
$mysqli = new mysqli(spf, dbuser, dbpw, db);
$stmt = $mysqli->prepare("INSERT INTO staffbranch
(sbranch_name)
VALUES (?)");
$stmt->bind_param("s", $sbranch_name);
$result = $stmt->execute();
if ($result == true && $stmt->affected_rows>0) {
echo "<b>". $check . "</b><br>";
}
else
{
echo '<p>Please <a href="addstaffb.php">Click Here</a> to return</p>';
}
$stmt->fetch();
$stmt->close();
$mysqli->close();
}
else
{
echo '<p>Please <a href="addstaffb.php">Click Here</a> to return</p>';
}