0

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))
{ 
$i++;
?>    
    <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

<script>
$(document).ready(function() {
$("#standardnameb").click(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; 
        }


$.post("ajax.php", 
{ 
standdis:standdis,
chkId:chkId
},
function(response){ 
if(response==0){ 
var str = "Inserted Successfully";
var result = str.fontcolor("green"); 
$("#disp4").html(result);
$("#ediths").hide();
 }
else {
var str = "Already Inserted..! Please Edit Below ";
var result = str.fontcolor("green"); 
$("#disp4").html(result);
<!--$('#ramu').load(' #div1');
-->
$("#ediths").show();
 }
});
});
});
</script>

and my ajax page

if(isset($_REQUEST['standdis']) && isset($_REQUEST['chkId'])){
$standdis=mysql_real_escape_string($_REQUEST['standdis']);
$chkId=mysql_real_escape_string($_REQUEST['chkId']);
$a=mysql_query("select * from   st_name_assign_st_cat where s_id='$standdis' ")or die(mysql_error());
$row=mysql_num_rows($a);
if($row==0){
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";
}else{
echo  $standdis;
}
}

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

5
Contributors
4
Replies
19
Views
2 Years
Discussion Span
Last Post by diafol
0

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)

0

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.

0

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?

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.