I am trying to insert value in database through ajax. There rows which are coming in while loop from database. I have added one column in each row which have button. On click of button I am submitting the values in database its working fine.
But problem is that it inserts value from first row only. Need help. Thanks in advance.
Not getting solution for problem
PHP Code :
<td><div class="form_style">
<input type="hidden" name="crs" id="crs" value="<?php echo $crs; ?>">
<input type="hidden" name="clg" id="clg" value="<?php echo $clg; ?>">
<button id="FormSubmit">Apply Now</button>
<img src="images/loading.gif" id="LoadingImage" style="display:none" />
</div></td>
Ajax and javascript Code :
<script type="text/javascript">
$(document).ready(function() {
$("#FormSubmit").click(function (e) {
e.preventDefault();
$("#FormSubmit").hide();
$("#LoadingImage").show();
var myData = {
crs: $('#crs').val(),
clg: $('#clg').val()
};
jQuery.ajax({
type: "POST",
url: "response.php",
dataType:"text",
data:myData,
success:function(response){
$("#responds").append(response);
$("#crs").val('');
$("#clg").val('');
$("#FormSubmit").show();
$("#LoadingImage").hide();
},
error:function (xhr, ajaxOptions, thrownError){
$("#FormSubmit").show();
$("#LoadingImage").hide();
alert(thrownError);
}
});
});
});
</script>
Response.php
<?php
$crs = $_POST["crs"];
$clg = $_POST["clg"];
$strsreg="insert into add_delete_record (id, content, content1) values('', '$crs', '$clg')";
$resultsreg=mysql_query($strsreg) or die(mysql_error());
?>