如何处理两个下拉post值?

enxuqcxy  于 2021-06-19  发布在  Mysql
关注(0)|答案(1)|浏览(276)

我默认有三个下拉列表。第一个下拉列表值将影响第二个和第三个下拉列表的可见性。例如,选择选项1、隐藏第3个下拉列表、显示第2个下拉列表。第二个和第三个下拉列表将保存数据库中同一列的值。

<select class="ui fluid selection dropdown dd" name="category1" id="category1">
    <i class="dropdown icon"></i>
    <option value="">Which category does this fall into?</option>
    <option value="1">Gestures</option>
    <option value="2">Etiquette</option>
</select>
<?php if(isset($_POST['category1'])) { $category1 = $_POST['category1']; }?>

<div class="category2" >
   <select class="ui fluid selection dropdown dd" name="category2" id="category2" >
        <i class="dropdown icon"></i>
        <option value="">Be specific...</option>
        <option value="1">Friendly gestures</option>
        <option value="2">Gestures of respect</option>
        <option value="3">Salutes</option>
        <option value="4">Celebratory gestures</option>
        <option value="5">Finger-counting</option>
        <option value="6">Obscene gestures</option>
        <option value="7">Taunts</option>
        <option value="8">Head motions</option>
        <option value="9">Other gestures</option>
    </select>
</div>
<?php if(isset($_POST['category2'])) { $category2 = $_POST['category2']; }?>

<div class="category3" style="display:none!important;">
    <select class="ui fluid selection dropdown dd" name="category3" id="category3">
        <i class="dropdown icon"></i>
        <option value="">Be specific...</option>
        <option value="10">Greetings</option>
        <option value="11">Making payment</option>
        <option value="12">Visiting someone's house</option>
        <option value="13">Gifts and gift-giving</option>
        <option value="14">Table manners</option>
        <option value="15">Eating and drinking</option>
        <option value="16">Funerals</option>
        <option value="17">Bars and restaurants</option>
        <option value="18">Driving</option>
        <option value="19">Business etiquette</option>
        <option value="20">Hierarchy and honoring the elder</option>
    </select>
</div>
<?php if(isset($_POST['category3'])) { $category3 = $_POST['category3']; }?>

现在,$category2和$category3表示数据库中的同一列。如果我要进行insert查询,如何确保其中一个下拉值已发布并将被存储?

mysqli_query($link,"INSERT INTO practices(category1,category2) VALUES('$category1','$category2 or $category3')")

我试过这个,然后

<?php if(isset($_POST['category2'])) { $category2 = $_POST['category2']; }?>
<?php if(isset($_POST['category3'])) { $category2 = $_POST['category3']; }?>

这一个只适用于其中一个下拉列表,错误插入另一个。任何帮助都将不胜感激

ig9co6j1

ig9co6j11#

将以前发布的值保存在隐藏字段中,然后使用第二个下拉列表再次发布。

<div class="category3" style="display:none!important;">

<?php if(isset($_POST['category2'])) 
{ 
    echo'<select name="pre_category" >
    <option selected="selected" value="'.$_POST['category2'].'">'.$_POST['category2'].' </option> 
    </select>';
 } ?>
    <select class="ui fluid selection dropdown dd" name="category3" id="category3">
        <i class="dropdown icon"></i>
        <option value="">Be specific...</option>
        <option value="10">Greetings</option>
        <option value="11">Making payment</option>
        <option value="12">Visiting someone's house</option>
        <option value="13">Gifts and gift-giving</option>
        <option value="14">Table manners</option>
        <option value="15">Eating and drinking</option>
        <option value="16">Funerals</option>
        <option value="17">Bars and restaurants</option>
        <option value="18">Driving</option>
        <option value="19">Business etiquette</option>
        <option value="20">Hierarchy and honoring the elder</option>
    </select>
</div>

现在您可以从pre\u类别中找到值

相关问题