I have a list of variables (var1, var2, ...). Now I'd like to check these variables using several conditions and print out an error message if the condition is true.
As there are many "checks" that should be done I saved the "conditions" in a MySQL-DB (varchar):
condition errormsg
--------------------------------------------------------
$var1!=1 && $var1!=2 var1 should be 1 or 2
$var1=='' var1 is missing
$var3<0 & $var3>10 var3 should be between 0 and 10
Now I'd like to check these variables using the eval-Function:
$res=mysqli_query($con, "SELECT * FROM conditions");
while($row=mysqli_fetch_object($res)){
if(eval($row->condition))
echo $row->errormsg;
}
Can this work or is there a better solution without eval()? Thank you for your help!