I am beginner in web development and know basic things. When creating project for practice implementing JavaScript in PHP file got stuck in this issue of putting PHP variable in the JavaScript. I am using apache xampp for PHP.
<?php
$name = "Mack Mack";
echo '<script>alert("<?php echo $name ?>");</script>';
/* this show <?php echo $name ?> */
?>
<html>
<title>TEST</title>
<body>
<h1>welcome</h1>
<div id="divid">check javascript</div>
<script type="text/javascript">
document.getElementById("divid").innerHTML += ' running';
alert("<?php echo $name ?>" + " from the html script section" );
</script>
</body>
</html>
the alert works fine for the PHP variable in the html section scripting, but doesnot work as expected in PHP section.