首页 > 解决方案 > 我选择时选项中的选择

问题描述

当我在选项中选择“事件赞助”然后运行代码时,我对编码有疑问。if()当我在选项中选择“活动赞助”时,如何在这里编写代码?下面是我的编码:

<label for="cp2" class="control-label col-lg-4">Merchant</label>
    <div class="col-lg-5">
        <select class="form-control required" id="branch_id3" name="branch_id3">
            <option value="" selected>Please Select</option>
            <option id="1"value="1">Event Sponsored</option>
            <option id="2" value="2">Normal Merchant</option>
         </select>
    </div>
     <?php
        $key_relationship_8[] = 'id_user';
        $val_relationship_8[] = convert_db_value($_POST['filter_id2']); 
        $key_relationship_8[] = 'type';
        $val_relationship_8[] = convert_db_value(3);
        $key_relationship_8[] = 'id_transaction_main';
        $val_relationship_8[] = convert_db_value($record_id2);  
        $key_relationship_8[] = 'credit';
        $val_relationship_8[] = convert_db_value($_POST['sub_total_rm']* (6/100));       
        $key_relationship_8[] = 'created';
        $val_relationship_8[] = convert_db_value($cur_dt);
        $key_relationship_8[] = 'createdby';
        $val_relationship_8[] = convert_db_value($user_name);
        $key_relationship_8[] = 'modified';
        $val_relationship_8[] = convert_db_value($cur_dt);
        $key_relationship_8[] = 'modifiedby';
        $val_relationship_8[] = convert_db_value($user_name);

        if(){               //how to code when I select Event Sponsored then run below the code?
            $row_insert8 = db_conn_insert('transaction_credit', $key_relationship_8, $val_relationship_8);
            $sql_insert8 = $row_insert8['sql'];
            $error_insert8 = $row_insert8['error'];
            $record_id8 = $row_insert8['record_id'];
            unset($key_relationship_8);
            unset($val_relationship_8);
        } else ($row_insert8) {
            echo 'Saved successfully';
            echo $sql_insert8; 
        }
?>

标签: phphtml

解决方案


您的Event Sponsored选项的值为1

我假设您的表单正在使用POST方法。

那么 if 语句可能是 -

if($_POST['branch_id3'] === 1) { }


推荐阅读