avihai1;10959065 wrote:try using it in a function.
<?php
if( isset($_SESSION['cust_id']) ){
echo "<script type='text/javascript'>";
echo "function setVar() {";
echo "var cust_name = '" . $_SESSION['fname'] . " " . $_SESSION['lname'] . "';";
echo " }";
echo "</script>\n";
}
?>
"var cust_name" is meeningless in function scope, since it will not be reachable from anywhere else this way. It would need to either be returned from the function so that you can retrieve it later or kept in global scope.
On the other hand, since the input with id 'name' holds the same value, there is little reason to keep it in a variable as well, which in turn means you could just as well
echo '<input type="text" ... value="'.$fname.' '.$lname.'"/>';
Either way, you should neither use this data in get query strings nor as post data. It could be changed, and you allready have it as session data anyway. As such, the only reason to use it on the page is if you want to show the user that they are "Logged in as: John Doe". So you don't even need the input to hold this data.