Problem with Echoing a string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Anarking
Forum Newbie
Posts: 24
Joined: Wed Feb 11, 2009 11:29 am

Problem with Echoing a string

Post 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?
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Problem with Echoing a string

Post by Mark Baker »

Code: Select all

 
for ($x = 1; $x <= $fields; $x++) {
    $req = 'required'.$x;
    echo "Required =  ".$_POST[$req]."<br />";
}
 
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Re: Problem with Echoing a string

Post 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]
Anarking
Forum Newbie
Posts: 24
Joined: Wed Feb 11, 2009 11:29 am

Re: Problem with Echoing a string

Post by Anarking »

ah cheers


that'll do it
Post Reply