my code-
<?php
session_start();
$_SESSION['errors']="failed";
?>
<head>
function myfunc()
{
alert(<?php echo $_SESSION['errors']; ?>);
}
</head>
<body onload="myfunc();">
but alert msg is not popping up.
Two errors in your code:
<script>
tagsTry this:
<?php
session_start();
$_SESSION['errors']="failed";
?>
<head>
<script>
function myfunc()
{
alert('<?php echo $_SESSION["errors"]; ?>');
}
</script>
</head>
You might want to put the myfunc()
in window.load
event or some click
event to test it. Additionally, as rightly suggested by ThiefMaster, you may want to use the addslashes
function for the $_SESSION["errors"]
in the alert
.
Note: It is assumed that file extension for your code is php.
PHP will just print out failed
, it won't print out the string delimiters along with it, so make sure you put them in:
function myfunc()
{
alert("<?php echo $_SESSION['errors']; ?>");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With