• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 397
  • Last Modified:

PHP Code from Database - Won't Work

The code stored in the Database is this:

filter_var($Array_Post['value'], FILTER_VALIDATE_EMAIL) == false

I'm trying to read it out via this:

}elseif($Array_Validation_Response['rule']){

I've tried this:

}elseif(eval($Array_Validation_Response['rule'])){

When the code is placed, it doesn't function as expected.  The validation rule from the database is NOT used, and the validation to properly catch an INVALID data component.

Someone know how to get this code from the database and make it work?


0
SMabs
Asked:
SMabs
  • 4
  • 4
1 Solution
 
SMabsAuthor Commented:
TO FURTHER EXPLAIN:

$Array_Validation_Response['rule'] is holding the code from the database (see below)

$Array_Validation_Response['rule']   -> contains this -> filter_var($Array_Post['value'], FILTER_VALIDATE_EMAIL) == false


I'm trying use the Code from the Database in an evaluation... but it's not working.  
It works hard coded of course, but when rendered from the database, it doesn't work.
0
 
ramelongCommented:
Try this intead of the "elseif()":

Sometimes you just cannot eval anything...
In this case I think that the eval() is performed, but the boolean result you recive into the "elseif" is related to de perform itself (whether works o not) and not to the result of the inner comparison.

The example may be enhanced in order to allow using other boolean operands...
}else{
    list($filter,$value)=explode('==',$Array_Validation_Response['rule']);
    $filter=eval($filter);
    if($filter=$value){

Open in new window

0
 
SMabsAuthor Commented:
That line is part of a much larger code piece, and must remain intact with the ELSEIF.....

The problem is simply that the code segment from the database is NOT being executed - it seems to be skipped over completely.

Here is a larger code segment where you can see how this is implemented - keep in mind, this is still a small portion of a larger code piece meant to have Dynamic Rules via DB:


                            // invalid -------
                            }elseif(filter_var($Array_Post['value'], FILTER_VALIDATE_EMAIL) == false){
                            //}elseif(eval($Array_Validation_Response['rule'])){

                                  switch($Mode){
                                        case 1:
                                              echo $Array_Validation_Response['response_invalid'].'+'.$Array_Validation_Response['icon_invalid_url_small'].'+'.$Array_Validation_Response['response_div_id'].'+invalid';
                                        break;

                                        case 2:
                                              echo ' *Email '.$Array_Validation_Response['response_invalid'].'* ';
                                        break;
                                  }
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
SMabsAuthor Commented:
The above works... however if I remark out the hard coded version, and use the EVAL() version, it doesn't work.  No errors as is (code segment in DB has a ; at the end of it), it just doesn't seem to evaluate/execute the code...


More Ideas?
0
 
ramelongCommented:
Yes...
Your problem is because eval must eval PHP sentences (filter_var($Array_Post['value'], FILTER_VALIDATE_EMAIL) == false is not a sencetnce)...
I think this must works:
$evalResult will have the result of the stored comparison...

This is instead of the elseif, if you need to conserve the "elseif()", you must to perform the eval before the "if()"...
0
 
ramelongCommented:
I miss the code...
}else{
    eval('$evalResult=('.$Array_Validation_Response['rule'].')?true:false;');
    if($evalResult) {

Open in new window

0
 
SMabsAuthor Commented:
excellent. Thanks for the advice
0
 
ramelongCommented:
You're welcome. Good luck with the rest!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now