Solved

PHP Code from Database - Won't Work

Posted on 2010-08-17
8
390 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
calculated column 12 74
mimic google as my ip 11 54
phpmyadmin 3 33
WordPress Themes 10 34
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

920 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

18 Experts available now in Live!

Get 1:1 Help Now