I am getting response as standard id in my project & i need to pass this value to php variable any body help me.

My PHP page

<div class="checkbox check-success"> <?php
$b=mysql_query("select * from standard_names ")or die(mysql_error());
$count  = mysql_num_rows($b);
$i = 0;
$breakafter=5; ?><?php
while($row = mysql_fetch_array($b))
    <input type="checkbox" class="chkNumber" id="<?php echo $row['sn_id']; ?>" value="<?php echo $row['sn_id']; ?>" />
    <label for="<?php echo $row['sn_id']; ?>"><?php echo $row['s_names']; ?></label>

     <?php  if($i % $breakafter == 0){?> <br><?php }
?>   </div>

MY Jquery page

$(document).ready(function() {
var standdis = $("#standdis").val();
    if ($('.chkNumber:checked').length) {
          var chkId = '';
          $('.chkNumber:checked').each(function () {
            chkId += $(this).val() + ",";
          chkId = chkId.slice(0, -1);

        else {
          alert('Nothing Selected');
          return false; 

var str = "Inserted Successfully";
var result = str.fontcolor("green"); 
else {
var str = "Already Inserted..! Please Edit Below ";
var result = str.fontcolor("green"); 
<!--$('#ramu').load(' #div1');

and my ajax page

if(isset($_REQUEST['standdis']) && isset($_REQUEST['chkId'])){
$a=mysql_query("select * from   st_name_assign_st_cat where s_id='$standdis' ")or die(mysql_error());
mysql_query("insert into   st_name_assign_st_cat(s_id,sn_id,status,c_date) values ('$standdis','$chkId','0','$c_date')") or die(mysql_error());
echo "0";
echo  $standdis;

Any body help me how to pass response to php variable dynamically

i don't know if it is posible to be done. But for me, it is not a good idea to assign a ajax result into php variable(mixing clint side and server side scripting)

PHP scripts run on the server, obviously, so you would need to post the data back once the AJAX request had finished. You could do that either by submitting the form or doing another AJAX request aimed at the target PHP code.

Well, you can't "just" pass it to PHP. You will need to work with it in Javascript. If you need it in PHP, maybe you shouldn't be handling this stuff with AJAX at all?

Member Avatar

Any chance that you can indent your code and povide some whitespace between assignments? ? Very difficult to follow.