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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error concatenating a string containing php 2

Status
Not open for further replies.

maharg

Technical User
Mar 21, 2002
184
Hi

I have a code which is basically a form containing a button, which has a value of $w, which I create in a loop, to make several copies of the form, each with a different value...

Basic form...
Code:
<tr>
<td style="background:transparent">
<form name="input" method="post" action="<?php echo $_SERVER['SCRIPT_NAME']?>">
<input type="hidden" name="id" value="1">
<input type="submit" name="submit" value="1">
</form> </td></tr>


Form when in a loop...

Code:
<?php
echo "<table><tr>";
$i=1;
while($i<=10)
{ 
$w=$i;
if ($w<10){$w=("00".$w);}
else if (($w<100)&&($w>9)){$w=("0".$w);}
else $w=$w;
$button='<td style="background:transparent">';
$button.='<form name="input" method="post" action="<?php echo $_SERVER['SCRIPT_NAME']?>">';
$button.='<input type="hidden" name="id" value="'.$w.'">';
$button.='<input type="submit" name="submit" value="'.$w.'">';
$button.='</form> </td>';
echo $button;
$i ++;
echo "</tr></table>";
?>

I get an error due to the form action method containing a php snippet, and can't fathom out how to get round that.

Any suggestions would be much appreciated!

Thanks in advance,

Graham
 
You are already in PHP - you don't need to go into it again. Try changing
Code:
$button.='<form name="input" method="post" action="<?php echo $_SERVER['SCRIPT_NAME']?>">';
to
Code:
$myform=$_SERVER['SCRIPT_NAME'];
$button.='<form name="input" method="post" action="' . $myform . '">';

If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Several things wrong there.

The error showing up is due to having PHP tags inside a PHP variable.

Since you are already in the PHP scope the PHP tags there are unnecessary.

You are also missing a closing brace for your while statement, which will generate another error.


Code:
<?php
echo "<table><tr>";
$i=1;
while($i<=10)
{ 
$w=$i;
if ($w<10){$w=("00".$w);}
else if (($w<100)&&($w>9)){$w=("0".$w);}
else $w=$w;
$button='<td style="background:transparent">';
$button.='<form name="input" method="post" action="[red]' . $_SERVER['SCRIPT_NAME']. '[/red]">';
$button.='<input type="hidden" name="id" value="'.$w.'">';
$button.='<input type="submit" name="submit" value="'.$w.'">';
$button.='</form> </td>';
echo $button;
$i ++;
[COLOR=white red]}[/color]
echo "</tr></table>";
?>

By the way, this:

Code:
else $w=$w;

Is completely pointless as you are assigning the variable to itself. So its of course equal to itself, because it already is what it is.



----------------------------------
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.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top