I'm trying to create a plugin for wordpress where the form stores data in a database. I'm trying to make a submit button to update the status (field) of one row from 0 to 1 but its updating all the column, how can i make to update only the selected one.

Look at the code...

<table class="widefat">
<tr><th class="row-title"><?php esc_attr_e( 'Application', 'aa' ); ?></th>
   <th class="row-title"><?php esc_attr_e( 'Name', 'aa' ); ?></th>
<th><?php esc_attr_e( 'Email', 'aa' ); ?></th>
<th><?php esc_attr_e( 'Message', 'aa' ); ?></th>
<th><?php esc_attr_e( 'Time', 'aa' ); ?></th>
<th><?php esc_attr_e( 'Birthplace', 'aa' ); ?></th>
<th><?php esc_attr_e( 'Birthday', 'aa' ); ?></th>
<th><?php esc_attr_e( 'Sex', 'aa' ); ?></th>
<th><?php esc_attr_e( 'Status', 'aa' ); ?></th>
<?php foreach($client_msg as $client): ?>
<td><?php esc_attr_e($client->name,'aa');?></a></strong></td>
<td><?php esc_attr_e($client->name,'aa');?></td>
<td><?php esc_attr_e($client->email,'aa');?></td>
<td><?php esc_attr_e($client->msg,'aa');?></td>
<td><?php esc_attr_e($client->time,'aa');?></td>
<td><?php esc_attr_e($client->birthplace,'aa');?></td>
<td><?php esc_attr_e($client->birthday,'aa');?></td>
<td><?php esc_attr_e($client->Sex,'aa');?></td>
<td><input type="submit" name="activate" id="activate" value="Activate"       onclick="change()" /></td>
<?php endforeach;?>


<script type="text/javascript">
function change(){

$sql="UPDATE wp_applications SET status = '1'" ;
$result = mysql_query($sql) or die(mysql_error());



That how it looks in wordpress the form that collects the data from databaseenter image description here

I need to change the field in database through that button but when i click as i mention it changes for all records.

the idea of this is to create a plugin which will be used for applications and then select candidates for interview.

closed as off-topic by TheDeadMedic, Howdy_McGee, Mayeenul Islam, Pieter Goosen, cybmeta Nov 25 '15 at 7:20

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.


Well I would add another parameter to the change() function like id. I am a little bit confused that your PHP code is wrapped in JavaScript Tags :D

In PHP i would do it like that:

function change($id) {
    $sql="UPDATE wp_applications SET status = '1' WHERE id = '$id'";

In the form i assume the id is stored in id column:

<input type="submit" name="activate" id="activate" value="Activate"       onclick="change($client->id)" />
  • i tried it, and removed the javascript tags they were useless and did everything as u said but the status on the table is not being update... do u have any other idea – sisco Nov 24 '15 at 16:47
  • 1
    I wonder that there was anything changing before. You use PHP in a JavaScript function. This can not work! – nipeco Nov 24 '15 at 16:50
  • I would try to solve this by using AJAX AJAX in Plugins – nipeco Nov 24 '15 at 16:52
  • it worked if i specify for example the id (WHERE id='1') but that is not what im needing lol.. anyway thanks – sisco Nov 24 '15 at 16:52

Depends on how you plan on storing the data.

If you just want arbitrary data to store via form user input, I use Formidable Pro plugin. It's very powerful and has many options for manipulating and viewing data.

If you are wanting to tie the data to the user meta, i have been playing with this approach: https://patrickshampine.com/2014/updating-user-meta-admin-ajax-frontend/ which allows the front end to edit outside of profile page.

At the same time if you want to use all wordpress provides you, you can do an all inclusive "profile page," since it looks like all your data is user related, and allow users to update their profiles. Add fields to the profile page like this:


The last option I have used successfully and it's pretty clean. You'll just need to add fields as desired.


PS: usually you want to enqueue any javascript you use within wordpress via enqueue_script().

Not the answer you're looking for? Browse other questions tagged or ask your own question.