2014-03-13 110 views
0

我是新的OOP PHP中,我仍然在学习,我有一个表单位置名称填充通过JQuery/HTML形式使用下拉字段具有相同的名称,我的问题是当我尝试在MySQL数据库中插入,我没有选择的值,php数组下拉字段没有插入到数据库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>';  
     } 

    } 
} 

请指点。谢谢

+0

请观看本次讲座:https://www.youtube.com/watch?v=z_LxkB-Pgf0 –

回答

0

你需要每个表单元素的唯一名称,用php你可以使用region[]。这会给你一个你的服务器脚本中的数组。

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

+0

您好感谢对此事发表评论,反正它说的错误:警告:array_filter()期望参数1是数组,字符串给定和urrent()期望参数1是数组,null在 –

+0

@JaysonLacson中给出你是否已将所选表单元素的名称从'region'更改为'region [] '? –

+0

hi @Preston是,它被更改为区域[]。 –