Current location: Hot Scripts Forums » Programming Languages » PHP » Injecting a string into an If Statement ?


Injecting a string into an If Statement ?

Reply
  #1 (permalink)  
Old 07-21-06, 06:54 AM
nova912's Avatar
nova912 nova912 is offline
Code Guru
 
Join Date: Sep 2004
Location: Traverse City, MI, USA
Posts: 821
Thanks: 0
Thanked 0 Times in 0 Posts
Injecting a string into an If Statement ?

ok... this is the code..

PHP Code:

// THE REQUIRED QUESTIONS FOR EACH SURVEY AND ADDED ARGUMENTS FOR EACH QUESTION

    
$rq[1] = array(1,2,3,4,5,6,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24,25,26,27,28,30,31,34,38,40,41,42,43,44,45,46,47,49,50,51,53,55,56,57,58,59,60,61,62,63,64,65,66,67);
    
$rq[2] = array(1,2,4,5,7,9,11,12,14,16,18,19,21,23,25,27,29,30,32,33,35,37);
    
$rq[3] = array(1,2,3,4,5,6,8,9,11,13,15,17,19,20);
    
$aa[3][4] = '&& $q[3] == "1"';
    
$rq[4] = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,20,21,22,23,24,26,28,29,30,31,32,33,34,35,38,39,40,41,42,43,44,45,46,47,48,49,50,52,53,54,55,56,58,59,60,61);
    
$rq[5] = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,23,24,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41);
    
$rq[6] = array(1,2,3,4,5,6,7,8,10,11,12,13,14,16,17,19);
    
$rq[7] = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28);
    
$rq[8] = array(1,2,3,4,6,7,8,10,11,13,15,17,19,20,21,22);
    
$rq[9] = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33);
    
$rq[10] = array(1,2,3,4,5,6,7,8,9,10,11,12,13,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,35,36,37,38);
    
    
// FIND ERRORS
    
$count count($rq[$survey_number]);
    for (
$i=0;$i$count;$i++)
        {
        if(isset(
$aa[$survey_number][$i]))
            {
            
$aa_echo $aa[$survey_number][$i];
            }
        else
            {
            
$aa_echo "";
            }
        if(
$q[$rq[$survey_number][$i]] == "NULL")
            {
            echo 
$rq[$survey_number][$i].': Is null and its not ok.<br>';
            }
        else
            {
            echo 
$rq[$survey_number][$i].': Is '.$q[$rq[$survey_number][$i]].' not null.<br>';
            }
        } 
The code is working AS IS but what i want to do (what i cant figure out) is how do i inject a string into an if statment so it reads the string as is and not check the string VAR like so

PHP Code:

if($q[$rq[$survey_number][$i]] == "NULL"// normal


if($q[$rq[$survey_number][$i]] == "NULL" $aa_echo// with a string that should read as...

if($q[$rq[$survey_number][$i]] == "NULL" && $q[3] == "1"
Its a simple question that i cant find an answer to =/

Last edited by nico_swd; 07-21-06 at 02:05 PM. Reason: Merged posts
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-21-06, 11:48 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Ah, I think I understand what you're trying to do. Maybe eval() helps in this case?

http://us2.php.net/manual/en/function.eval.php

And on a side note, you may want to have a look at range().
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-21-06, 11:53 AM
nova912's Avatar
nova912 nova912 is offline
Code Guru
 
Join Date: Sep 2004
Location: Traverse City, MI, USA
Posts: 821
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by nico_swd
Ah, I think I understand what you're trying to do. Maybe eval() helps in this case?

http://us2.php.net/manual/en/function.eval.php

And on a side note, you may want to have a look at range().
Yeah i have a post-it note on my computer saying "look into range" lol, but really i have been trying eval() all friggin morning and i just cant get it to work, i have spent like 3 hours trying any and all variations of eval() i have seen in the manual =/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-21-06, 12:03 PM
nova912's Avatar
nova912 nova912 is offline
Code Guru
 
Join Date: Sep 2004
Location: Traverse City, MI, USA
Posts: 821
Thanks: 0
Thanked 0 Times in 0 Posts
The only thing I have had any luck with is actually getting eval to work with but i still can get eval to dump the var as is into the if statement /bash things!

PHP Code:

// FIND ERRORS

    
$count count($rq[$survey_number]);
    eval(
"for (\$i=0;\$i< \$count;\$i++)
        {
        \$if_state = '\$q[\$rq[\$survey_number][\$i]] == \"NULL\"';
        if(isset(\$aa[\$survey_number][\$i]))
            {
            \$if_state .= \$aa[\$survey_number][\$i];
            }
        if(\"\$if_state\")
            {
            echo \$rq[\$survey_number][\$i].': Is '.\$q[\$rq[\$survey_number][\$i]].' null and its not ok.<br>';
            }
        else
            {
            echo \$rq[\$survey_number][\$i].': Is '.\$q[\$rq[\$survey_number][\$i]].' not null.<br>';
            }
        };"
); 
The above produces this...

1: Is NULL null and its not ok.
2: Is 1 null and its not ok.
3: Is 1 null and its not ok.
4: Is NULL null and its not ok.
5: Is NULL null and its not ok.
6: Is NULL null and its not ok.
8: Is NULL null and its not ok.
9: Is NULL null and its not ok.
11: Is NULL null and its not ok.
13: Is NULL null and its not ok.
15: Is NULL null and its not ok.
17: Is NULL null and its not ok.
19: Is NULL null and its not ok.
20: Is NULL null and its not ok.


Question 1: NULL
Question 2: 1
Question 3: 1
Question 4: NULL
Question 5: NULL
Question 6: NULL
Question 7: NULL
Question 8: NULL
Question 9: NULL
Question 10: NULL
Question 11: NULL
Question 12: NULL
Question 13: NULL
Question 14: NULL
Question 15: NULL
Question 16: NULL
Question 17: NULL
Question 18: NULL
Question 19: NULL
Question 20: NULL


Gunna take a break, im throughly stumped.

Last edited by nico_swd; 07-21-06 at 02:04 PM. Reason: Merged posts
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-21-06, 03:04 PM
nova912's Avatar
nova912 nova912 is offline
Code Guru
 
Join Date: Sep 2004
Location: Traverse City, MI, USA
Posts: 821
Thanks: 0
Thanked 0 Times in 0 Posts
WOOT! FINNALY FRIGGIN 4 HOURS OF FIDDLING AND I GOT IT LOL.

PHP Code:

// THE REQUIRED QUESTIONS FOR EACH SURVEY AND ADDED ARGUMENTS FOR EACH QUESTION

    
$rq[1] = array(1,2,3,4,5,6,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24,25,26,27,28,30,31,34,38,40,41,42,43,44,45,46,47,49,50,51,53,55,56,57,58,59,60,61,62,63,64,65,66,67);
    
$rq[2] = array(1,2,4,5,7,9,11,12,14,16,18,19,21,23,25,27,29,30,32,33,35,37);
    
$rq[3] = array(1,2,3,4,5,6,8,9,11,13,15,17,19,20);
    
$aa[3][4] = ' && '.$q[3].' == "1"';
    
$rq[4] = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,20,21,22,23,24,26,28,29,30,31,32,33,34,35,38,39,40,41,42,43,44,45,46,47,48,49,50,52,53,54,55,56,58,59,60,61);
    
$rq[5] = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,23,24,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41);
    
$rq[6] = array(1,2,3,4,5,6,7,8,10,11,12,13,14,16,17,19);
    
$rq[7] = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28);
    
$rq[8] = array(1,2,3,4,6,7,8,10,11,13,15,17,19,20,21,22);
    
$rq[9] = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33);
    
$rq[10] = array(1,2,3,4,5,6,7,8,9,10,11,12,13,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,35,36,37,38);
    
    
// FIND ERRORS
    
$count count($rq[$survey_number]);
    for (
$i=0;$i$count;$i++)
        {
        
$if_state '$q['.$rq[$survey_number][$i].'] == "NULL"';
        if(isset(
$aa[$survey_number][$rq[$survey_number][$i]]))
            {
            
$if_state .= $aa[$survey_number][$rq[$survey_number][$i]];
            }
        if(eval(
"return ".$if_state.";"))
            {
            echo 
$rq[$survey_number][$i].': Is NULL and NOT ok. : '.$if_state.'<br>';
            }
        else
            {
            echo 
$rq[$survey_number][$i].': is NULL and IS ok. : '.$if_state.'<br>';
            }
        } 

Last edited by nova912; 07-21-06 at 03:39 PM. Reason: Revised
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem returning interest in bankaccount program psi3000 Everything Java 6 03-27-06 02:14 PM
BankAccount object oreinted help psi3000 Everything Java 6 03-16-06 11:07 AM
help to turn a filelist in to a winamp playlist mike-wigan Windows .NET Programming 0 10-18-05 12:10 PM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM


All times are GMT -5. The time now is 01:56 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.