Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP Code from Database - Won't Work

Posted on 2010-08-17
8
Medium Priority
?
396 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

618 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