2014-03-13 154 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是,它被更改爲區域[]。 –