php - Inserts wrong value to MySQL table -
i have dynamic list mysql table on php page html part below 10-20 times per page. if click submit-button insert stuff database player_id id of first record on page. need able click 1 in middle example , insert correct value mysql table. can point me right direction on how achieve this? thanks!
html part:
<input type="hidden" name="player_id" value="<?php echo $player_id;?>"> <input name="insert" type="submit" class="button" value="3">
js part:
$(document).ready(function(){ $('[name=insert]').click(function(){ var player_id=$("[name=player_id]").val(); $.post('process.php', {player_id: player_id, points: 3}, function(data){ $("#message").html(data); $("#message").hide(); $("#message").fadein(1500); }); return false; }); });
php/mysql part (process.php):
**connection stuff here $player_id=$_post['player_id']; $points=$_post['points']; $query=mysql_query("insert p_points (player_id,points) values('$player_id','$points')");
and before says, yes change pdo :) want make work correctly first, after can learn pdo properly.
you try
$(document).ready(function(){ $('.button').click(function(){ var player_id = $(this).prev().val(); alert(player_id); $.post('process.php', {player_id: player_id, points: 3}, function(data){ $("#message").html(data); $("#message").hide(); $("#message").fadein(1500); }); return false; }); });
working fiddle http://jsfiddle.net/ysbam/
Comments
Post a Comment