Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8734645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:53:05+00:00 2026-06-13T09:53:05+00:00

I have a problem updating MySQL rows using Jquery. This is my current code.

  • 0

I have a problem updating MySQL rows using Jquery.

This is my current code.

<script type="text/javascript">
$(document).ready(function(){
$(".insert").click(function(){

var id=$("#id").val();
var ip=$("#ip").val();
var permissions=$("#permissions").val();
var password=$("#password").val();
var key=$("#key").val();

$.post('myscript.php?action=updateAPIuser', {id: id, ip: ip, permissions: permissions,     password: password, key:key },
function(data){
$("#message").html(data);
$("#message").hide();
$("#message").fadeIn(1500); 
});
return false;
});
});   
</script>

This is the html:

<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<th>Customer</th>
<th>Permission</th>
<th>IP</th>
<th>Key</th>
<th>Password</th>
<th>Date added</th>
<th>Action</th>
</tr>
<tr class="record" id="record-1"><td>John Doe</td>
<td><select id="permissions" name="permissions" />
<option value="ro" selected>Read Only</option>
<option value="rw">Read Write</option>
</select></td>
<td><input type="text" id="ip" name="ip" value="1.1.1.13">
<input type="hidden" id="id" name="id" value="1"></td>
<td><input type="text" id="key" name="key" value="mijnkey"></td>
<td><input type="text" id="password" name="password" value="password000"></td>
<td>2012-10-24 20:48:25</td><td><a class="insert" title="Update data" href="#"><img src="images/icons/save.png" title="Save" alt="Save"></a> 
</td></tr>

<tr class="record" id="record-2"><td>Jane Doe</td>
<td><select id="permissions" name="permissions" />
<option value="ro" selected>Read Only</option>
<option value="rw">Read Write</option>
</select></td>
<td><input type="text" id="ip" name="ip" value="2.2.1.13">
<input type="hidden" id="id" name="id" value="1"></td>
<td><input type="text" id="key" name="key" value="janeskey"></td>
<td><input type="text" id="password" name="password" value="pass000"></td>
<td>2012-10-24 20:48:25</td><td><a class="insert" title="Update data" href="#"><img src="images/icons/save.png" title="Save" alt="Save"></a> 
</td></tr>
</table>

And ofcourse I have php for updating the MySQL row.

The problem is this: When I click on Save (aka Update) the Jquery always updates the row with ID 1. No matter what row I click.

So my question is: how can I change the code, so that the correct row gets updates?

Cheers,
Hub

PS This is my PHP-code for updating the row:

function updateAPIuser($req){
global $db_whmcs, $_LANG;    

$id = $req['id'];
$ip = $req['ip'];
$permissions = $req['permissions'];
$password = $req['password'];
$key = $req['key'];
$updated = date("Y-m-d H:i:s");

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0



  $query = "UPDATE `mod_powerdns_api` SET 
`ip` = '".$ip."',
`key` = '".$key."',
`permissions` = '".$permissions."',
`updated` = '".$updated."', 
`password` = '".$password."' 
WHERE `id` = ".$id;

mysql_query($quer) or pdns_die('Can not update user'.mysql_error());

} // end

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:53:06+00:00Added an answer on June 13, 2026 at 9:53 am

    First of all you shouldn’t use duplicate id’s.

    From http://www.w3schools.com/tags/att_global_id.asp

    Definition and Usage

    The id attribute specifies a unique id for an HTML element (the value
    must be unique within the HTML document).

    You can get the correct id by using the following code:

    var id = $(this).find('[name="id"]').val();
    

    The other elements can also be found the same way:

    $(".insert").bind('click', function(){
        var tr = $(this).parents('tr');
    
        var id = tr.find('[name="id"]').val();
        var ip = tr.find('[name="ip"]').val();
        var permissions = tr.find('[name="permissions"] option:selected').val();
        var password = tr.find('[name="password"]').val();
        var key = tr.find('[name="key"]').val();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a problem updating several rows of a mysql table using a
I have problem with my query on C, I’m using the oci8 driver. This
I'm using Doctrine 2 ORM and I have this problem. I have three Entities,
I have a problem updating a value of a variable in a shell script
I have a problem updating an MySQL Database. I want to be able to
I have problem in updating mysql table. While the problem seems somewhat strange I'm
problem with passing variables (php, sql, jquery draggable) Hi, this is my problem: updating
Have a problem with updating an existing record of my DB. In my view
i have a problem with updating my textview. i am making a c2dm app.
I have a little problem in updating date. My first table is DONOR donor-nic----username-----status

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.