Jarod Posted December 24, 2009 Share Posted December 24, 2009 How do I use eval()? Man it's so confusing, I thought I had it at first. It work, but not until I really needed... I used it with a function and it's not doing so! // set_session("username", "user1"); function set_session($session, $username) { eval($_SESSION['$session'] = $_POST['$username']); } Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 24, 2009 Share Posted December 24, 2009 How do I use eval()? Man it's so confusing, I thought I had it at first. It work, but not until I really needed... I used it with a function and it's not doing so! // set_session("username", "user1"); function set_session($session, $username) { eval($_SESSION['$session'] = $_POST['$username']); } Maybe you should look at the eval function and read what it actually does. Quote Link to comment Share on other sites More sharing options...
trq Posted December 24, 2009 Share Posted December 24, 2009 The first thing is that variables are not interpolated within single quotes, besides, you don't need eval for what you are doing. function set_session($session, $postitem) { $_SESSION[$session] = $_POST[$postitem]; } Quote Link to comment Share on other sites More sharing options...
Jarod Posted December 24, 2009 Author Share Posted December 24, 2009 OK wut did I do wrong in this??? Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\practices\test\index.php on line 1 eval(" if( !isset($_SESSION['server']) ) { $_SESSION['server'] = \"Direct TV\"; echo $_SESSION['server']; } else { echo \"<b>Server</b> already set! (\". $_SESSION['server'] .\")\"; } "); Quote Link to comment Share on other sites More sharing options...
Jarod Posted December 24, 2009 Author Share Posted December 24, 2009 OK wut did I do wrong in this??? Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\practices\test\index.php on line 1 eval(" if( !isset($_SESSION['server']) ) { $_SESSION['server'] = \"Direct TV\"; echo $_SESSION['server']; } else { echo \"<b>Server</b> already set! (\". $_SESSION['server'] .\")\"; } "); Quote Link to comment Share on other sites More sharing options...
co.ador Posted December 24, 2009 Share Posted December 24, 2009 What's that you want to do with the EVAL() function? Quote Link to comment Share on other sites More sharing options...
trq Posted December 24, 2009 Share Posted December 24, 2009 What exactly are you trying to do? You don't need eval(). Quote Link to comment Share on other sites More sharing options...
premiso Posted December 24, 2009 Share Posted December 24, 2009 $ needs to be escaped inside of double quotes: eval("if( !isset(\$_SESSION['server']) ) { \$_SESSION['server'] = \"Direct TV\"; echo \$_SESSION['server']; } else { echo \"<b>Server</b> already set! (\". \$_SESSION['server'] .\")\"; } "); Quote Link to comment Share on other sites More sharing options...
premiso Posted December 24, 2009 Share Posted December 24, 2009 Please do not make repeat posts. Your questions has been answered in your other post. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.