Hi, could someone please tell me how I can join two php string variables?! Here's my code:

for ($i=0; $i<$children; $i++) 
{
$child_name.$i = htmlentities($_POST['child_name$i']);
$child_age.$i = htmlentities($_POST['child_age$i']);
$child_mom.$i = htmlentities($_POST['child_mom$i']);
$child_require.$i = htmlentities($_POST['child_require$i']);
} 

???

THANKS!

    What exactly is the trouble from what you have there its correct

    However id do this differently
    $_POST['child_name$i']

    as

    $_POST['child_name'.$i]

      I don't know what the problem is!! ... I've managed to get around it with:

      for ($i=0; $i<$children; $i++)  
      { $child_name = "child_name".$i; $child_age = "child_age".$i; $child_mom = "child_mom".$i; $child_require = "child_require".$i; $child_name = htmlentities($_POST['child_name'.$i]); $child_age = htmlentities($_POST['child_age'.$i]); $child_mom = htmlentities($_POST['child_mom'.$i]); $child_require = htmlentities($_POST['child_require'.$i]); }

        php will not parse single quotes for variables like this-->>
        'child_name$i'

          The original code has a concatenation taking place on the left side of the = sign, which doesn't make sense.

          Compute on the right. Assign to the left.

            So there's no way to make a variable like that ... then assign a value to it in the same line? do you have to double it all up like I did in the end there.

            and those single quotes seem to be working??? :rolleyes:

              Look up "variable variables" in the PHP manual.

              But don't do it. If you are trying to make a collection of like items, use an array.

                ahhh, sweet! ... Thanks for the guidence yelvington! 🙂 I have a lot to learn about Arrays!

                  Write a Reply...