Update a row in a wordpress table

Question

I currently have a plugin that displays my table fields in a table. I have made the table into a form, put the table cells as inputs, with the ‘value’set to the current column value. I have also created a button with value = row id.

I want to be able to edit the cells, but typing in the input field and when I press the update button it saves the new values to the database.

For some reason my code isn’t working.

This is how it displays each row.. This bit seems to work ok

  echo "<tr>
        <td><input name='postcode' value='".$postcode."'></td>
        <td><input name='town' value='".$town."'></td>
        <td><input name='county' value='".$county."'></td>
        <td><button name='update' value='".$id ."'>UPDATE</button></td>
                <td><button name='delete' value='".$id ."'>DELETE</button></td>
        </tr>
        ";

This is the update code which is not working

if (isset ($_POST['update'])){
     $details = array (
        'postcode'=>$_POST['postcode'],
        'town'=>$_POST['town'],
        'county'=>$_POST['county']
     );
     $wpdb->update($tablename, array (
        'postcode'=>$_POST['postcode'],
        'town'=>$_POST['town'],
        'county'=>$_POST['county']
     ), array('id' => $_POST['update'] ));
   }

Any sugestions on how to get it to work would be much appreciated.

0
Victoria Whitehead 3 years 2020-06-07T18:11:01-05:00 0 Answers 84 views 0

Leave an answer

Browse
Browse