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 <? Link to comment https://forums.phpfreaks.com/topic/38950-why-is-this-not-working-eval/ 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 Link to comment https://forums.phpfreaks.com/topic/38950-why-is-this-not-working-eval/#findComment-187367 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 Link to comment https://forums.phpfreaks.com/topic/38950-why-is-this-not-working-eval/#findComment-187369 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 Link to comment https://forums.phpfreaks.com/topic/38950-why-is-this-not-working-eval/#findComment-187376 Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 $y = "if(\".$checkone.$condition.\"){ $ok = 'yes';}"; Link to comment https://forums.phpfreaks.com/topic/38950-why-is-this-not-working-eval/#findComment-187380 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. Link to comment https://forums.phpfreaks.com/topic/38950-why-is-this-not-working-eval/#findComment-187448 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 Link to comment https://forums.phpfreaks.com/topic/38950-why-is-this-not-working-eval/#findComment-187452 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? Link to comment https://forums.phpfreaks.com/topic/38950-why-is-this-not-working-eval/#findComment-187464 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? Link to comment https://forums.phpfreaks.com/topic/38950-why-is-this-not-working-eval/#findComment-187470 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"; Link to comment https://forums.phpfreaks.com/topic/38950-why-is-this-not-working-eval/#findComment-187474 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 Link to comment https://forums.phpfreaks.com/topic/38950-why-is-this-not-working-eval/#findComment-187479 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 Link to comment https://forums.phpfreaks.com/topic/38950-why-is-this-not-working-eval/#findComment-187484 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. Link to comment https://forums.phpfreaks.com/topic/38950-why-is-this-not-working-eval/#findComment-187495 Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 nm nice Link to comment https://forums.phpfreaks.com/topic/38950-why-is-this-not-working-eval/#findComment-187509 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.