?
Solved

PHP Code from Database - Won't Work

Posted on 2010-08-17
8
Medium Priority
?
395 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

 

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
 
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …
Suggested Courses

765 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