0

I have a requirement where I have some conditions saved in DB. I am able to bring those conditions via my PHP code, But I am not able to execute them. I have shown one example below.

<? 

$z = ">100";//I get this value from the DB
$x = 80; // This value also comes from DB

if(exec("&1 &2",$x,$z))
  echo "Yes";
else
  echo "No";
?>

Also tried This

<? 

$z = ">100";
$x = 80;
if(eval("$x $z"))
  echo "Yes";
else
  echo "No";
?>
8
  • 2
    exec() is meant for shell commands. eval() runs dynamic code. Commented Aug 25, 2015 at 3:06
  • 1
    Not to be a troll, but remember, "If eval() is the answer, you're almost certainly asking the wrong question." -- Rasmus Lerdorf, BDFL of PHP Commented Aug 25, 2015 at 3:16
  • What happens when you try the second block of code? Commented Aug 25, 2015 at 3:40
  • php.net/manual/en/function.eval.php#114731 Commented Aug 25, 2015 at 3:42
  • I get this error. Parse error: syntax error, unexpected '=' in E:\wamp\www\test\test.php(3) : eval()'d code on line 1 Commented Aug 25, 2015 at 3:44

1 Answer 1

1

It should be, ( eval only accepts statements, not expressions)

$z = ">100";//I get this value from the DB
$x = 80; // This value also comes from DB


if(eval("return {$x} {$z};"))
  echo "Yes";
else
  echo "No";
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.