php - Looping over an array of inputs with the same name -


i'm making todo list , i've got working except 1 thing. need loop on inputs that's been submitted via form, these inputs have same name i've done storing them array. need loop on them can send them database 1 one. here's tried:

if (isset($_post['submit'])) {     $labelvalues = $_post['labelvalue[]'];      $i = 0;      while($i < sizeof($labelvalues)) {          $stmt = $db->prepare("insert tenta_table (text) values (:text)");         $stmt->bindparam(':text', $labelvalues[$i]);         $stmt->execute();         $i++;     } } 

html, inputs marked red:

inputs

but doesn't seem work, it's not giving me errors have nothing go on. going wrong here?

your $_post['labelvalue'] array if have named inputs correctly, <input type="text" name="labelvalue[]" /> create , array called labelvalue in post.

from there should able use current code 1 minor change

if (isset($_post['submit'])) {     $labelvalues = $_post['labelvalue'];      $i = 0;      while($i < sizeof($labelvalues)) {          $stmt = $db->prepare("insert tenta_table (text) values (:text)");         $stmt->bindparam(':text', $labelvalues[$i]);         $stmt->execute();         $i++;     } } 

above have change $labelvalues equal $_post['lablevalue'] rather $_post['labelvalue[]']


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -