Page 1 of 1

Problem with Echoing a string

Posted: Wed Mar 18, 2009 12:05 pm
by Anarking
Hi there


Im trying to print out something but im having errors with it

What I have is this

for ($x = 1; $x <= $fields; $x++)
{

echo "Required = {$_POST['required".$x."']}<br />";
}

It just prints out " Required = "

But when I print out

echo "Required = {$_POST['required1']}<br />";

It prints out what I want to print "Required = on"


It seems im making some basic error with the insertion of the $x variable but I cant figure it out

Can anyone help a brother?

Re: Problem with Echoing a string

Posted: Wed Mar 18, 2009 12:08 pm
by Mark Baker

Code: Select all

 
for ($x = 1; $x <= $fields; $x++) {
    $req = 'required'.$x;
    echo "Required =  ".$_POST[$req]."<br />";
}
 

Re: Problem with Echoing a string

Posted: Wed Mar 18, 2009 12:11 pm
by William
Anarking wrote:Hi there


Im trying to print out something but im having errors with it

What I have is this

for ($x = 1; $x <= $fields; $x++)
{

echo "Required = {$_POST['required".$x."']}<br />";
}

It just prints out " Required = "

But when I print out

echo "Required = {$_POST['required1']}<br />";

It prints out what I want to print "Required = on"


It seems im making some basic error with the insertion of the $x variable but I cant figure it out

Can anyone help a brother?
Change

Code: Select all

$_POST['required".$x."']
to

Code: Select all

$_POST['required'.$x]

Re: Problem with Echoing a string

Posted: Wed Mar 18, 2009 12:23 pm
by Anarking
ah cheers


that'll do it