php数组下拉字段不插入数据库mysql

时间:2014-03-13 03:01:43

标签: php jquery mysql

我是OOP PHP的新手,我还在学习,我有一个表单,其中的位置名称通过JQuery / HTML表单使用相同名称的下拉字段填充,我的问题是当我尝试在mysql数据库中插入,我没有得到选定的值,

        <div id="NCR" class="drop-down-show-hide">  
        <div class="field">
            <label for="region"> NCR </label>
            <select name="region" id="ncr region">
                <option value="">-- Choose --</option>
                <option value="1"> Region 1 </option>
                <option value="2"> Region 2 </option>
                <option value="3"> Region 3 </option>
            </select> 
        </div>  
    </div>


    <div id="CAR" class="drop-down-show-hide">
        <div class="field">
            <label for="field"> CAR </label>
            <select name="region" id="car region">
                <option value="">-- Choose --</option>
                <option value="4"> Region 4 </option>
                <option value="5"> Region 5 </option>
                <option value="6"> Region 6 </option>
            </select> 
        </div>  
    </div>


    <div id="region3" class="drop-down-show-hide">
        <div class="field">
            <label for="region"> CAMANABA </label>
            <select name="region" id="camanaba region">
                <option value="">-- Choose --</option>
                <option value="7"> Region 7 </option>
                <option value="8"> Region 8 </option>
                <option value="9"> Region 9 </option>
            </select> 
        </div>          
    </div>/HTML

PHP

if(Token::check(Input::get('token'))){
    $validate = new Validate();
    $validation = $validate->check($_POST, array(
        'apz_account' => array(
            'required' => true          
        ),
        'api_account' => array(
            'required' => true                      
        ),
        'wupos_tid' => array(
            'required' => true      
        ),
    ));

    if($validation->passed()){

        // check APZ account 
        $agent = DB::getInstance()->get('agent', array('apz_account', '=', Input::get('apz_account')));

        if(!$agent->count()){

                // check API account 
                $agent = DB::getInstance()->get('agent', array('api_account', '=', Input::get('api_account')));

                if(!$agent->count()){

                    $agent = new Agent();

                    try {


                        $agent->createAgentAccount(array(
                            'apz_account' => Input::get('apz_account'),
                            'api_account' => Input::get('api_account'),
                            'wupos_tid' => Input::get('wupos_tid'),
                            'region' => Input::get('region'),
                            'registered' => date('Y-m-d H:i:s'),
                        ));


                        //  print_r($agent);
                         // Session::flash('success', 'You have registered successfully.');
                         // Redirect::to('../../index.php');


                        } catch(Exception $e){
                            die($e->getMessage());
                    }



                    } else {

                    echo Input::get('api_account'), ' account is already exists';
                }

            } else {

            echo Input::get('apz_account'), ' account is already exists';
        }


    } else {
        foreach ($validation->errors() as $error) {
            echo $error, '<br>';    
        }

    }
}

请指教。谢谢

1 个答案:

答案 0 :(得分:0)

每个表单元素都需要唯一的名称,使用php可以使用region[]。这将为您提供服务器脚本中的数组。

然后当你得到值current(array_filter(Input::get('region')));