0

this is my url

db_control.php?workname=Test+message&worktype=1&workscore=10&multi%5B%5D=4&multi%5B%5D=24&frmsubmit=

this is my php code

if(isset($_REQUEST['frmsubmit']))
{
    echo $_REQUEST['workname']; echo '<br>';
    echo $_REQUEST['workscore'];echo '<br>';
    foreach($_REQUEST['multi'] as $mlti => $n)
    {
        echo $n;echo '<br>';
    }
}

I am getting this answer

Test message 10

$_REQUEST['multi'] returns empty why..?

these all from a form post(form method is get)

What i am doing wrong? kindly guide me in right way. thanks in advance.

this is my html code

<form enctype="multipart/form-data" class="form-horizontal ng-pristine ng-valid" id="work_assignment" method="get" action="<?=BASE_URL?>db_control.php" role="form">
    <div class="box-body">
        <label class="col-sm-3 control-label" for="name">Work Name<font class="redFont">*</font></label>
        <div class="controls col-sm-6">
            <input class="form-control" id="workname" required="required" name="workname" value="" type="text">
        </div>

    </div>
            <div class="box-body">
    <div class="row" id="field_name">
        <label class="col-sm-3 control-label" for="name">Work Type<font class="redFont">*</font></label>
        <div class="controls col-sm-6">
            <select class="select2-container form-control select2Field" id="worktype" name="worktype" onchange="hidescore(this)">
                                <option value="1">KRA</option>
                                <option value="2">Regular Task</option>
                                <option value="3">SELF Task</option>
                            </select>
        </div>                  
    </div>
            <div class="box-body">              
    <div class="row" id="field_namews">
        <label id="hidsco" class="col-sm-3 control-label" for="name">Work Score</label>
            <div class="controls col-sm-6">
            <input class="form-control" id="workscore" name="workscore" value="" type="text">
            </div>

    </div>

    <div class="row" id="field_name">
        <label class="col-sm-3 control-label" for="name">Employee<font class="redFont">*</font></label>
        <div class="controls col-sm-6" style="height:130px">
                            <select name="multi[]" multiple="multiple" style="height:100%"><!--onchange="setmail(this)"-->
                <option value="1">SudarshanSeshadri (1000)</option>
                <option value="3">Sonal Nahata (1010)</option>
                <option value="4">SujishV (1002)</option>
                <option value="33">JohnbabuAmose (0001)</option>
                <option value="34">GeethaVijay (1086)</option>
                <option value="35">BabuAmose (2100000)</option>
                <option value="36">SudhakarJeevan (102)</option>                                                                    </select>
        </div>

    </div>

    <div class="control-group row">
            <div class="controls col-sm-9">
            <button type="submit" class="btn btn-primary pull-right" name="frmsubmit"><i class="fa fa-save"></i> Save</button>
            <button type="button" class="btn pull-right" style="margin-right:5px;" onclick="cancelsave()"><i class="fa fa-times-circle-o"></i> Cancel</button>
            </div>

    </div>

John Babu
  • 15
  • 4

1 Answers1

-1

The right way to do this would be to pass all values of multi in one parameter multi in the following way.

Use:

http://example.com/workname=Test+message&worktype=1&workscore=10&multi=4,24&frmsubmit=

Instead of:

http://example.com/workname=Testmessage&worktype=1&workscore=10&multi[]=4&multi[]=24&frmsubmit=

And access the values of "multi" by using explode like this:

if(isset($_REQUEST['frmsubmit']))
{
    echo $_REQUEST['workname']; echo '<br>';
    echo $_REQUEST['workscore'];echo '<br>';
    $multiParam = explode(",",$_REQUEST['multi']);
    foreach($multiParam as $mlti => $n)
    {
        echo $n;echo '<br>';
    }
}

EDIT: Also read @EduardoFernandes's answer here for more information.

Community
  • 1
  • 1
bIgBoY
  • 417
  • 2
  • 12
  • thanks that variable multi[] is from dropdown multiple selection option. how can i do this..? – John Babu Dec 16 '15 at 08:12
  • That's not right. The way he dealt with multi parameters is perfect and way more elegant than yours. Also, what if one of the multi values include a comma? Bang! You got a splitted value. – Amarnasan Dec 16 '15 at 08:13
  • I provided an alternate solution to the problem he is facing. Why don't you enlighten us as to why it isn't working? @Amarnasan – bIgBoY Dec 16 '15 at 08:18
  • I enlighted you by saying I tried it and it worked. As you can see in my comment to his answer. – Amarnasan Dec 16 '15 at 08:18