Solved

PHP Code from Database - Won't Work

Posted on 2010-08-17
8
389 Views
Last Modified: 2013-12-13
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
Comment
Question by:SMabs
  • 4
  • 4
8 Comments
 

Author Comment

by:SMabs
ID: 33458220
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
 
LVL 6

Expert Comment

by:ramelong
ID: 33458612
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
 

Author Comment

by:SMabs
ID: 33458677
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
 

Author Comment

by:SMabs
ID: 33458689
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 6

Expert Comment

by:ramelong
ID: 33459137
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
 
LVL 6

Accepted Solution

by:
ramelong earned 500 total points
ID: 33459161
I miss the code...
}else{
    eval('$evalResult=('.$Array_Validation_Response['rule'].')?true:false;');
    if($evalResult) {

Open in new window

0
 

Author Closing Comment

by:SMabs
ID: 33460349
excellent. Thanks for the advice
0
 
LVL 6

Expert Comment

by:ramelong
ID: 33464700
You're welcome. Good luck with the rest!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now