golden14 Posted March 10, 2008 Share Posted March 10, 2008 I'm working on passing a lot of variables from Flash to PHP, and then back to Flash again. It works correctly when I run this: <?php for ($i=1; $i<31; $i++) { ${'rg1tName'.$i}=$_POST['rg1_'.$i]; if($i>1){ echo "&rg1_".$i. "=".${'rg1tName'.$i}; } else { echo "rg1_".$i. "=".${'rg1tName'.$i}; } } ?> But when I add more into the if/else statements (which I need to do), it doesn't work. <?php for ($i=1; $i<31; $i++) { ${'rg1tName'.$i}=$_POST['rg1_'.$i]; ${'rg2tName'.$i}=$_POST['rg2_'.$i]; if($i>1){ echo "&rg1_".$i. "=".${'rg1tName'.$i}; echo "&rg2_".$i. "=".${'rg2tName'.$i}; } else { echo "rg1_".$i. "=".${'rg1tName'.$i}; echo "rg2_".$i. "=".${'rg2tName'.$i}; } } ?> Using trial and error and commenting out different sections of the code and changing it (both the AS3 and the PHP), it seems like the problem is in the PHP in the echoing sections. Based on what you see here, is there something noticeably wrong? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/95331-incorrect-ifelse-statement/ Share on other sites More sharing options...
btherl Posted March 10, 2008 Share Posted March 10, 2008 I don't see anything obviously wrong (apart from the unusual use of variables instead of an array for ${'rg1tName'.$i}. That makes me nervous, but I guess it ought to work ) Is it possible that the url is too long? Quote Link to comment https://forums.phpfreaks.com/topic/95331-incorrect-ifelse-statement/#findComment-488269 Share on other sites More sharing options...
golden14 Posted March 10, 2008 Author Share Posted March 10, 2008 It's not pulling from a URL, Flash is storing text box strings in variables using the URLVariables method in AS3. I have 4 groups of variables, each with a different prefix (rg1, rg2, rg3 and rg4). It works no problem when I try it with just one. But when I add that second grouping in there, it will POST it without giving an error but the echo sections will give an error. Thanks anyway though! Quote Link to comment https://forums.phpfreaks.com/topic/95331-incorrect-ifelse-statement/#findComment-488277 Share on other sites More sharing options...
unsider Posted March 10, 2008 Share Posted March 10, 2008 Can't help very much, but just make sure your double checking all your variable names, etc.. Thorough spell check I suppose. Sorry I can't be of much help. Quote Link to comment https://forums.phpfreaks.com/topic/95331-incorrect-ifelse-statement/#findComment-488280 Share on other sites More sharing options...
Xajel Posted March 10, 2008 Share Posted March 10, 2008 I'm not that much with flash, but from what I read, Flash need each variable in it's own line <?php for ($i=1; $i<31; $i++) { ${'rg1tName'.$i}=$_POST['rg1_'.$i] . "\n"; ${'rg2tName'.$i}=$_POST['rg2_'.$i]; if($i>1){ echo "&rg1_".$i. "=".${'rg1tName'.$i} . "\n"; echo "&rg2_".$i. "=".${'rg2tName'.$i}; } else { echo "rg1_".$i. "=".${'rg1tName'.$i} . "\n"; echo "rg2_".$i. "=".${'rg2tName'.$i}; } } ?> just add "\n" at the end of each variable except the last one, so if you have three or four // 3 variables example echo "rg1_".$i. "=".${'rg1tName'.$i} . "\n"; echo "rg2_".$i. "=".${'rg2tName'.$i} . "\n"; echo "rg3_".$i. "=".${'rg3tName'.$i}; // 4 variables example echo "rg1_".$i. "=".${'rg1tName'.$i} . "\n"; echo "rg2_".$i. "=".${'rg2tName'.$i} . "\n"; echo "rg3_".$i. "=".${'rg3tName'.$i} . "\n"; echo "rg4_".$i. "=".${'rg4tName'.$i}; and so on Quote Link to comment https://forums.phpfreaks.com/topic/95331-incorrect-ifelse-statement/#findComment-488290 Share on other sites More sharing options...
btherl Posted March 10, 2008 Share Posted March 10, 2008 The echo sections give an error? What is the error? Quote Link to comment https://forums.phpfreaks.com/topic/95331-incorrect-ifelse-statement/#findComment-488294 Share on other sites More sharing options...
btherl Posted March 10, 2008 Share Posted March 10, 2008 Oh.. I just thought about your code's logic. It doesn't make sense. You can do it like this: $sep = ''; for ($i=1; $i<31; $i++) { ${'rg1tName'.$i}=$_POST['rg1_'.$i]; ${'rg2tName'.$i}=$_POST['rg2_'.$i]; echo $sep . "rg1_".$i. "=".${'rg1tName'.$i}; $sep = '&'; echo $sep . "rg2_".$i. "=".${'rg2tName'.$i}; } $sep will be blank for the first variable only, ensuring that you get a & in front of every subsequent variable. Quote Link to comment https://forums.phpfreaks.com/topic/95331-incorrect-ifelse-statement/#findComment-488299 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.