title: PHP CodeIgniter: My code to delete database data is not working correctly, can you spot the issue?
body: <p>Basically I am trying to delete database data when a use presses a delete button, the way this works is I have the data in the table, I collect it via an array of arrays (the arrays inside the array represent each record), pass it into the view, display each record (some of it), the user decides whether to delete it, if they press delete then the field data is posted back into my controller and passed into a model where it runs a query to delete the data based on the UID it has, this should work, but what is actually happening is that everything works and I don't get any errors, but the data isn't deleting, I suspect it is because the form isn't posting the data back properly, do some of you deep CI users know why? Here is relevant code:</p>
  
  <p>Controller:</p>
  
  <pre><code>public function clist() { //function to show the client list and edit/delete buttons
          $this-&gt;load-&gt;model('list_model');
          $fields = $this-&gt;list_model-&gt;listcliname();
          $data = array();
          $data['fields'] = $fields;
          $this-&gt;load-&gt;view('clientlist', $data);
          if ($_POST['del'] === 1) { //if the user selects the delete button then call model to delete the fields for the button they selected
          $fields = $_POST['fields'];
          $this-&gt;list_model-&gt;delcli($fields);
          }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>class list_model extends CI_Model {
  
  public function listcliname()
      {
          return $this-&gt;db-&gt;get('clients')-&gt;result_array(); //get an array of arrays (one array for each record in table)
      }
  public function delcli($fields)
      {
          $this-&gt;db-&gt;where('UID', $fields['UID']);
          $this-&gt;db-&gt;delete('clients', $fields);
      }
  
  }
  </code></pre>
  
  <p>view:</p>
  
  <pre><code>&lt;html&gt;
      &lt;body&gt;
  
              &lt;?php
              foreach($fields as $field) {
                   ?&gt;
                   &lt;ul&gt;
                   &lt;li&gt;
                   &lt;?php echo $field['name']; ?&gt;
                   &lt;/li&gt; 
                   &lt;li&gt;
                   &lt;?php echo $field['contact']; ?&gt;
                   &lt;/li&gt;
                   &lt;li&gt;
                  &lt;form action="clistedit" method="post"&gt;
                  &lt;button name="UID" type="submit" value="&lt;?php echo $field['UID']?&gt;"&gt;edit&lt;/button&gt;
                  &lt;input type="hidden" name="sub" value="1" /&gt;
                  &lt;/form&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                  &lt;form action="clist" method="post"&gt; 
                  &lt;input type="hidden" name="fields" value="&lt;?php $field ?&gt;" /&gt;
                  &lt;button name="del" type="submit" value="1"&gt;delete&lt;/button&gt;
                  &lt;/form&gt;
                  &lt;/li&gt;
                  &lt;/ul&gt;
  
                   &lt;?php
              }
  
              ?&gt;
  </code></pre>
  
  <p>(you can probably ignore the form with clistedit form action, that is working correctly)</p>
  
  <p>any help is appreciated, thanks!</p>
  
  <p>EDIT: It may be because what I am posting back is an array? I could split up the array and add multiple hidden submits to submit each value and then add them to an array again in my controller but I would like to avoid this.</p>