0
<script>
var test = 1;
<?php
$id = "document.write(test)" ;
//echo $id;
//here i want to run sql code 
?>
var id =<?php echo $id; ?>;
alert(id);
</script>

fist i want pass test value to php id second i wanna pass php id value to var id . when i run this code alert says Undefined . How to display id in a alert.

Dinoo
  • 27
  • 10

1 Answers1

1

You forgot to put quotes. id is a string, and PHP does not echo the quotes when it echoes a string. Change it to:

var id = "<?php echo $id; ?>";
afuous
  • 1,478
  • 10
  • 12