![](/img/trans.png)
[英]How to insert multiple selects dropdown values in database, php codeigniter
[英]php: how do i insert values into database from multiple dropdown list and added one text along with it
我有两个表'用 2 个下拉列表显示了它的数据,所以我想从两个下拉列表中添加那些选定的值,并想插入一个问题(文本)和一个单选按钮值! 请帮助我有点困惑:/怎么办?
这是代码
<div class="grid_10">
<div class="box round first">
<h2>Add / Edit Questions </h2>
<p>
</p>
</div>
</div>
<div class="grid_5">
<div class="box round">
<h2>
Add / Update Questions</h2>
<div class="block">
<p>
<table style="width:100%">
<tr>
<td>
<h2>Select Designation</h2>
<?php
$sql = "SELECT desg_name FROM 360d_designation";
$ds = mysql_query($sql) or die(mysql_error());
echo "<select>";
while($row = mysql_fetch_array($ds)){
echo "<option value='".$row["desg_id"]."'>".$row["desg_name"]."</option>";
}mysql_free_result($ds);
echo "</select>";
?>
</td>
<td>
<h2>Select Relation
</h2>
<?php
//<select id="id" name="selectstate" onChange="showCity(this.value)">
$sql = "SELECT rel_name FROM 360d_relations";
$rs = mysql_query($sql) or die(mysql_error());
echo "<select>";
while($row = mysql_fetch_array($rs)){
echo "<option value='".$row["rel_id"]."'>".$row["rel_name"]."</option>";
}mysql_free_result($rs);
echo "</select>";
//$rel = $row;
?>
</td>
</tr>
输入问题:
<?php if(isset($_POST["btns"])){ //<-----Inserting data in to databse $que_id = $_POST['que_id']; $Que_detail = $_POST['Que_detail']; $desg_id = $_POST['$ds']; $rel_id = $_POST['$rs']; $feedback_type = $_POST['$c1']; $msg=""; if($que_id==0) { $q = "insert into 360d_app_questions values(null,'{$Que_detail}','{$desg_id}','{$rel_id}','{$feedback_type}')"; $msg = "added"; } else { $q = "update 360d_app_questions set Que_detail ='{$Que_detail}' where que_id=".$que_id; $msg = "updated"; } $res = mysql_query($q,$con); if($res) echo "<h2>Question {$msg} sucessfully!!</h2>"; else echo "question cannot be {$msg}"; } ?> </center> </p> </div> </div> </div> <div class="grid_5"> <div class="box round"> <h2>View Questions </h2> <div class="block"> <p> <?php /* $qry = "select * from 360d_app_questions "; $res = mysql_query($qry,$con); if($res && mysql_num_rows($res)>0){ echo "<table cellspacing=10>". "<tr><th><h2>Questions Manager </h2></th><th><h2>     Edit</h2></th><th></th></tr>"; while($row = mysql_fetch_array($res)){ echo "<tr>". "<td><h2>$row[1]</h2></td>". "<td><a href='360d_addquestions.php?dept_id={$row[0]}'> <h2> ✉ <?php ?></h2></a></td>". "</tr>"; } echo "</table>"; */ ?> </p> </div> </div> </div> <div class="clear"> </div> </div> <div class="clear"> </div>
如果我理解你的标题问题,你应该给你两个选择一个名字,比如
<select name="test">
// Options here
</select>
<select name="test_2">
// Options here
</select>
要在 DB 上插入一些其他文本,我们可以通过不同的方式实现,一种是在您选择标签中执行以下操作:
echo "<option value='".$row["rel_id"]." / Details'>".$row["rel_name"]."</option>";
以及通过表单发送威胁数据的地方,您可以使用:
$exploded = explode('/', $_POST['test']);
然后你可以连接
或者您可以在插入数据库时插入文本,例如:
"INSERT INTO tableName(columnName) VALUES (value1+ ' ' + detail)"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.