php - How to pass 2 array in foreach using $_POST -
i trying insert dynamic form filed values database. insert these values in database,i trying apply foreach loop in mysql query code goes this:
if (isset($_post['submit_val'])) { if ($_post['elements'],$_post['quanity']){ foreach($_post['elements'] $elements){ foreach($_post['quantity'] $quantity){ $sql[] = "insert create_campaign (elements, quantity) values ('{$elements}','{$quantity}')"; } } foreach($sql $query){ mysql_query($query); } }
}
<div class="row col-md-12" ng-app="angularjs-starter" ng-controller="mainctrl"> <fieldset data-ng-repeat="choice in choices" name="records"> <label for="inputpassword3" class="col-md-1 control-label">elements</label> <div class="form-group col-md-3 "> <input type="text" placeholder="campaign name" ng-model="choice.name" class="form-control c-square c-theme input-lg" name="elements[]" multiple> </div> <label for="inputpassword3" class="col-md-1 control-label">quantity</label> <div class="form-group col-md-3" > <select class="form-control c-square c-border-2px c-theme" name="quantity[]"> <option value="1">100</option> <option value="2">200</option> <option value="3">300</option> <option value="4">400</option> </select> </div> <button type="button" class="btn c-theme-btn c-btn-uppercase btn-lg c-btn-bold c-btn-square" ng-click="addnewchoice()" id="add_field">add</button> <button ng-show="$last" ng-click="removechoice()" class="btn c-theme-btn c-btn-uppercase btn-lg c-btn-bold c-btn-square" >remove</button> </fieldset> </div> </div> </div> <div class="form-group"> <input type="text" placeholder="description" class="form-control c-square c-theme input-lg" name="description"> </div> <input class="btn c-theme-btn c-btn-uppercase btn-lg c-btn-bold c-btn-square" value="submit" type="submit" name="submit_val">
it's giving error , insertion of database not happening, do?
try use follows.. can perfect error if stuck this...
<?php if (isset($_post['submit_val'])) { if ($_post['elements'] && $_post['quantity']){ foreach($_post['elements'] $elements){ foreach($_post['quantity'] $quantity){ echo $sql = "insert create_campaign (elements, quantity) values ('{$elements}','{$quantity}')"; //mysql_query($sql) or die(mysql_error); } } } } ?> <form method="post"> <div class="row col-md-12" ng-app="angularjs-starter" ng-controller="mainctrl"> <fieldset data-ng-repeat="choice in choices" name="records"> <label for="inputpassword3" class="col-md-1 control-label">elements</label> <div class="form-group col-md-3 "> <input type="text" placeholder="campaign name" ng-model="choice.name" class="form-control c-square c-theme input-lg" name="elements[]" multiple> </div> <label for="inputpassword3" class="col-md-1 control-label">quantity</label> <div class="form-group col-md-3" > <select class="form-control c-square c-border-2px c-theme" name="quantity[]"> <option value="1">100</option> <option value="2">200</option> <option value="3">300</option> <option value="4">400</option> </select> </div> <button type="button" class="btn c-theme-btn c-btn-uppercase btn-lg c-btn-bold c-btn-square" ng-click="addnewchoice()" id="add_field">add</button> <button ng-show="$last" ng-click="removechoice()" class="btn c-theme-btn c-btn-uppercase btn-lg c-btn-bold c-btn-square" >remove</button> </fieldset> </div> </div> </div> <div class="form-group"> <input type="text" placeholder="description" class="form-control c-square c-theme input-lg" name="description"> </div> <input class="btn c-theme-btn c-btn-uppercase btn-lg c-btn-bold c-btn-square" value="submit" type="submit" name="submit_val"> </form>
wiki
Comments
Post a Comment