BreakBreak Posted February 17, 2007 Share Posted February 17, 2007 $y = "if(".$checkone.$condition."){ $ok = 'yes';}"; eval($y); I get the following error: Parse error: parse error in /var/www/html/insidethecity.php(109) : eval()'d code on line 1 Line 109 is the code i showed. line 1 is <? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 17, 2007 Share Posted February 17, 2007 The "line 1" in the error message refers to the first line of the eval'd code, not the lines of your script. Before you do the eval(), echo the string and post it here. The error message is saying something is wrong with the string you're trying to use eval() on. Ken Quote Link to comment Share on other sites More sharing options...
BreakBreak Posted February 17, 2007 Author Share Posted February 17, 2007 Thanks. Well i got that echo'd too on the page and it says this: 7 >= 5 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 17, 2007 Share Posted February 17, 2007 That is not a valid PHP statement, which is why you're getting the error. Ken Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 $y = "if(\".$checkone.$condition.\"){ $ok = 'yes';}"; Quote Link to comment Share on other sites More sharing options...
BreakBreak Posted February 17, 2007 Author Share Posted February 17, 2007 $y = "if(\".$checkone.$condition.\"){ $ok = 'yes';}"; This does not work. Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 ya looks like javascript to me I dont understand it if($checkone.$condition){ $ok = yes lets say.. checkone = 100 condition = + if(100+){ $ok = yes wtf? + what?? see.. thats the problem i think Quote Link to comment Share on other sites More sharing options...
BreakBreak Posted February 17, 2007 Author Share Posted February 17, 2007 Er... What? checkone = 100 condition = > 1 Did you read the posts above before you posted? Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 ok makes sense $y = "if(\".$checkone.$condition.\"){ $ok = \"yes\";}"; maybe works? Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 TO be honest if statement for 1 line sucks .. use condition ? true : false; $checkone.$condition ? $ok = "YES" : $ok = "NO"; Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 17, 2007 Share Posted February 17, 2007 The problem is that since you're enclosing the string to be eval'd in double quotes, PHP is trying to use the value of the variable "$ok" in the string. If that variable isn't set or doesn't translate into a valid symbol name, you get the error. You can either escape the "$ok" with a backslash: <?php $y = "if(".$checkone.$condition."){ \$ok = 'yes';}"; ?> or surround the string with single quotes: <?php $y = "if(".$checkone.$condition.'){ $ok = "yes";}'; ?> Ken Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 17, 2007 Share Posted February 17, 2007 If you want to use sspokes idea, you would use: <?php $y = '$ok =('.$checkone.$condition.')?"yes":"no";'; ?> Ken Quote Link to comment Share on other sites More sharing options...
BreakBreak Posted February 17, 2007 Author Share Posted February 17, 2007 I used your idea, and it worked. Thank you for your time ken. Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 nm nice 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.