Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP post method passing

Status
Not open for further replies.

dagoat10

Programmer
Jun 3, 2010
74
US
I am trying to pass a variable to a php form but it is not passing through. The lines are the following:

Code:
echo "<form action='create_table_test2.php', method='post'>";
while($NumCols > 0)
{
    echo "<input type='text' name='Col$ColNum' />
    $ColNum++;
    $NumCols--;
    echo "<br>";
}
echo $NumCols2;
echo "<input type='hidden' name='Cols' value=$NumCols2 />";
echo "<br>";
echo "<input type='submit' name='Change' value='Change Table' />";
echo "</form>";

then i am trying to retrive it like this:
Code:
print $_POST["$Col$ColNum"];
or this
Code:
print $_POST['Col$ColNum'];
is it not possible to do this?
 
Neither one of those would work directly. The first one would need the value of the $Col variable to be the 'Col' string. So it matches the name of your fields.

And the second one simply doesn't expand the variables when between single quotes. Perhaps what you want to do is:

Code:
$_POST[[red]"[/red][blue]Col[/blue][green]$ColNum[/green][red]"[/red]]

Alternatively:
Code:
$_POST[[red]"[/red][blue]Col[/blue][red]"[/red] . [green]$ColNum[/green]]


Provided $ColNum is set to a number that exists in your input loop.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top