Update table records with jquery and mysql using php -


i need updating selected item list populated via php , updated jquery, here have:

my update.php front-end

 <?php include_once('db.php'); ?>   <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en"   "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">    <html xmlns="http://www.w3.org/1999/xhtml">    <head>   <meta http-equiv="content-type" content="text/html; charset=utf-8" />  <title>update collected</title>  <link rel="stylesheet" href="css/style.css" type="text/css" media="print, projection, screen" />  <link rel="stylesheet" href="css/bootstrap.css" type="text/css" media="screen" />  <link rel="stylesheet" href="css/bootstrap-responsive.css" type="text/css" media="screen" />  </head>    <body>   <?php    $sql="select * qrnumber";   $result=mysql_query($sql);     ?>  <div class="container-fluid main">        <div class="row-fluid ">             <div class="span12">            <span class="success"></span>     <table cellpadding="0" cellspacing="0" id="tablesorter-demo" class="tablesorter table table-striped">   <thead>   <tr>    <th>id</th><th>name</th><th>points</th><th>collected</th><th>action</th>   </tr>  </thead>   <?php while($row = mysql_fetch_array($result)) : ?>   <tr id="<?php echo $row['id']; ?>"> <td><?php echo $row['id']; ?></td> <td><?php echo $row['name']; ?></td> <td><?php echo $row['points']; ?></td> <td><?php echo $row['total']; ?></td> <!-- , on --> <td>     <input id="total" class="required" type="text" name="total">   <button class="update_btn" rel="<?php echo $row['id']; ?>">update</button>  </td>  </tr>   <?php endwhile; ?>  <?php   // close connection   mysql_close();    ?>   </table>   </div>    </div>    </div>    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>       <script type="text/javascript" src="js/jquery.tablesorter.js"></script>     <script>     $(document).ready(function(){          $(function() {             $("#tablesorter-demo").tablesorter({sortlist:[[0,0],[2,1]], widgets: ['zebra']});     $("#options").tablesorter({sortlist: [[0,0]], headers: {              3:{sorter: false}, 4:{sorter: false}}});    );     $('.update_btn').click(function(){     $('.success').text("loading...");      var id = $(this).attr('rel');      var total = $('#total').val();     $.post('call.php', {id:id, total:total}, function(data) {         alert(data);     });  });     });  </script>   </body> </html> 

this process.php file

 <?php   include_once('db.php');  var_dump($_post);  if (isset($_post['collected'])){ $collected =  mysql_real_escape_string(htmlentities($_post['collected']));  }  $id = $_post['id'][0];   $total = $_post['total'];   echo $id. $total;    mysql_query("update qrnumber set total='$total'    id='$id'");     ?> 

the issue when post number input field, makes connection processing php file, not update content, connects db , passes values update.php process file(call.php). then, sets of records '0', can help, please.

thanks,

jv

your $_post wrong in php. php creates array of values in $_post/$_get if fieldname submitted client ends [] characters. e.g.

will produce following $_post array:

$_post = array(     'not_an_array' => 'bar'     'is_an_array' => array (        0 => 'baz'        1 => 'qux'     ) ); 

since id andtotalyou're submitting in ajax call don't have[]` in names, they'll plain single values in php, e.g.

$id = $_post['id']; $total = $_post['total']; 

and nod you're still vulnerable sql injection attacks, since you're trying use $id directly in query without escaping either. any external data going query string attack vector. cannot escape of values , assume you're safe.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -