php - getting plain array text when updating mysql record -


so have table fields this, want able edit each username/email etc if check box selected.

echo '<td><input type=checkbox name=checkbox[]  value='. $row['id'] .'       ></td>';  echo '<td><input type=text     name=username[]  value='. $row['username'] .' ></td>';  echo '<td><input type=text     name=email[]     value='. $row['email'] .'    ></td>';  echo '<td><input type=text     name=adress[]    value='. $row['adress'] .'   ></td>';

and script, array plain text result each input, btw im using query email test first

if(isset($_post['edit']))  {      if(isset($_post['checkbox'])) {          $id_array = $_post['checkbox'];           $id_count = count($_post['checkbox']);          for($i=0; $i < $id_count; $i++) {              $id = $id_array[$i];              $query = ("update members set email = '". $_post['email'] ."' id = '". $id ."'");		              $result = $conn->query($query);               if($result) {                  echo "ok";              }              else {                  echo "<br><br>error: " . $conn->error;              }           }      }  }

first off, vulnerable sql injection attacks. enjoy having server pwn3d.

secondly, you're stuffing post array directly query, incorrect. since you're using [] naming hack in form fields, $_post['email'] going array of values form, , need more like

.... values ('$_post[email][$i]', ...)                            ^^^^ 

(note array index) access individual values in sub-array.

remember, php, using array in string context gives literal word array, , not array's contents:

$foo = array(1,2,3); echo "$foo"; // outputs 'array' echo "$foo[1]"; // outputs '2' 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -