Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new in OOP PHP and I am still learning, I have a form where name of locations is populated through JQuery/HTML form using drop-down field with same name, my problem is when I try to insert in mysql database, I did not get the selected value,

        <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>';    
        }

    }
}

Please advice. Thank you

share|improve this question
 
please watch this lecture: youtube.com/watch?v=z_LxkB-Pgf0 –  tereško Mar 13 at 6:01
add comment

1 Answer

You need unique names for each form element, with php you can use region[]. this will give you an array in your server script.

Then when you get the value do current(array_filter(Input::get('region')));

share|improve this answer
 
Hi Thanks for comment, anyway it says in the error: Warning: array_filter() expects parameter 1 to be array, string given and urrent() expects parameter 1 to be array, null given in –  Jayson Lacson Mar 13 at 4:48
 
@JaysonLacson Did you change the name of your select form elements from region to region[]? –  Preston S Mar 13 at 14:32
 
hi @Preston yes it is changed to region[]. –  Jayson Lacson 2 days ago
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.