Jump to content

Incorrect if/else statement?


golden14

Recommended Posts

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!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.