php:如何从多个下拉列表中将值插入数据库并添加一个文本

时间:2015-02-18 15:00:38

标签: php jquery mysql

我有两张桌子'用2下拉列表显示其数据,所以我想从下拉列表中添加这些选定的值,并希望插入一个问题(文本)和一个单选按钮值! PLZ帮我一点点迷惑:/怎么办呢?

这是代码

<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> &nbsp &nbsp  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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;✉ <?php ?></h2></a></td>".
                    "</tr>";


                    }
                    echo "</table>";
    */          ?>







                </p>
            </div>
        </div>
    </div>
    <div class="clear">
    </div>
</div>
<div class="clear">
</div>

1 个答案:

答案 0 :(得分:0)

如果我理解你的标题问题,你应该给你们两个选择一个名字,比如

<select name="test">
// Options here
</select>

<select name="test_2">
// Options here
</select>

要在数据库上插入一些其他文本,我们可以通过不同的方式实现这一点,一个在你的选择标签中做类似的事情:

echo "<option value='".$row["rel_id"]." / Details'>".$row["rel_name"]."</option>";

您通过表格发送威胁数据的地方可以使用:

$exploded = explode('/', $_POST['test']);

然后你可以连接

或者您可以在插入数据库时​​插入文本,如:

"INSERT INTO tableName(columnName) VALUES (value1+ ' ' + detail)"

希望它可以帮到你