这里的场景。下面的代码是我从表格中检索数据" koti_images"并以选择框的形式显示在页面上,该选择框已经成功。
所以问题是,有可能确保用户从选择框中选择值,在这种情况下是"计划"然后单击“保存”,该数据将保存在mysql的其他表中。我已经创建了新表" koti_imagedigital"但我不知道如何将选中的值传递给此表。我是新手,所以希望你们都能帮助我。谢谢。
<form name="form_update" method="post" action="testkoti.php">
<?php
$con=mysqli_connect("localhost","root","","koti");
//============== check connection
if(mysqli_errno($con))
{
echo "Can't Connect to mySQL:".mysqli_connect_error();
}
//=============================
//This creates the drop down box
echo "<select name= 'plan_id'>";
echo '<option value="">'.'--- Please Select Plan ---'.'</option>';
$query_display = mysqli_query($con,"SELECT * FROM koti_images");
while($row=mysqli_fetch_array($query_display))
{
echo "<option value='". $row['file_name']."'>".$row['file_name']
.'</option>';
}
echo '</select>';
?>
<div class="box-footer">
<a href="#" class="btn btn-warning">Cancel</a>
<button href = "#" type="submit" class="btn btn-primary pull-right">Save & Exit</button>
</div>
</div>
</form>
答案 0 :(得分:0)
如果我正确理解了您的问题,您可以执行类似的操作来获取值,然后继续将值插入数据库。如果您想输出它,请记得清理该值。并在插入数据库时使用预准备语句和绑定参数。
<?php
if(isset($_POST['plan_id'])) {
$var = $_POST['plan_id'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// prepare and bind
$stmt = $conn->prepare("INSERT INTO your_table (row) VALUES (?)");
$stmt->bind_param("s", $var);
$stmt->execute();
$stmt->close();
echo "Saved.";
}
?>
<form name="form_update" method="post" action="testkoti.php">
<select name="plan_id">
<option value="first">First</option>
<option value="second">Second</option>
<option value="third">Third</option>
</select>
</form>