Forum Moderators: coopster

Message Too Old, No Replies

echo inside echo causing problems

php echo

         

tdog

3:53 am on Feb 1, 2005 (gmt 0)

10+ Year Member



Hi all,

I am struggling with trying to get a page to load itself again. the PHP_SELF part seems to be the problem. Is it possible to use and echo inside a print or echo statement? I get this type of error

"Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in ...."

Any assistance would be great

while ($line4 = mysql_fetch_array($result4, MYSQL_ASSOC))
{

echo "\t<tr>\n";
foreach($line4 as $col_value)
{
echo "<td><font size=2>$col_value</td>";

}
echo "\t</tr>";
$i = $i + 1;
if($i==5)
{
echo "<tr>";
echo "<td colspan=5>";
print "<form method=\"post\" action=\"<?php echo $_SERVER['PHP_SELF'];?>\">\";<font size=2>Organisational Goal ID: <input type=\"text\" name=\"delete\"><input type=\"submit\" name=\"submit\" value=\"Delete Vulnerability\"></form>";
echo "</td>";
echo "</tr>";
$i=1;
}
}
echo "</table>\n";

Thanks and Cheers
Ty

supermanjnk

4:03 am on Feb 1, 2005 (gmt 0)

10+ Year Member



add this wherever it needs to be

$self = $_SERVER['PHP_SELF'];

and put this instead

print "<form method=\"post\" action=\'<?php echo $self;?>\'>\";<font size=2>Organisational Goal ID: <input type=\"text\" name=\"delete\"><input type=\"submit\" name=\"submit\" value=\"Delete Vulnerability\"></form>";

see if that works.

tdog

4:09 am on Feb 1, 2005 (gmt 0)

10+ Year Member



Thank v much for the speedy reply!

Now it loads the page looking pretty much as it should however I hit the submit buttonof the form and I get the following error page.

"You don't have permission to access /< on this server."

Cheers Ty

supermanjnk

4:21 am on Feb 1, 2005 (gmt 0)

10+ Year Member



try just using action=\"$self\"

added - <? print "<form method=\"post\" action=\"$self\"><font size=2>Organisational Goal ID: <input type=\"text\" name=\"delete\"><input type=\"submit\" name=\"submit\" value=\"Delete Vulnerability\"></form>";?>

tdog

4:26 am on Feb 1, 2005 (gmt 0)

10+ Year Member



Permissions-wise all is fine I just don't think the echo inside print/echo is happy. I even tried the following to no avail. doh!

while ($line4 = mysql_fetch_array($result4, MYSQL_ASSOC))
{

echo "\t<tr>\n";
foreach($line4 as $col_value)
{
echo "<td><font size=2>$col_value</td>";

}
echo "\t</tr>";
$i = $i + 1;
if($i==5)
{

$e = "ec";
$h = "ho";
$self = $_SERVER['PHP_SELF'];
echo "<tr>";
echo "<td colspan=5><form method=\"post\" action=\"<?php $e$h $self?>\">\";<font size=2>Organisational Goal ID: <input type=\"text\" name=\"delete\"><input type=\"submit\" name=\"submit\" value=\"Delete Vulnerability\"></form>";
echo "</td>";
echo "</tr>";
$i=1;
}
}
echo "</table>\n";

supermanjnk

4:30 am on Feb 1, 2005 (gmt 0)

10+ Year Member



I edited my post while you were posting so check what i wrote.

tdog

4:33 am on Feb 1, 2005 (gmt 0)

10+ Year Member



Still no good after trying just /"$self/" thing. No page reload occurs just sort of sits there on the original page. Thanks heaps for the help. Frustration is quickly setting in. is there some other quick way of doing this that you know of?

tdog

4:42 am on Feb 1, 2005 (gmt 0)

10+ Year Member



Thanks for all your help! Great to have 2 minds on one problem. I took the extra "<?" ">" from your last edit and it works perfectly. Cheers Very Muchly

Ty

dmmh

8:45 am on Feb 1, 2005 (gmt 0)

10+ Year Member



try leaving action blank. works for me :)

ergophobe

6:06 pm on Feb 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




print "<form method=\"post\" action=\'<?php echo $self;?>\'>\";<font size=2>Organisational Goal ID:....

No can do. What this should print if you look at view source is

<form method="post" action='<?php echo $self;?>'>";<font size=2>Organisational Goal ID:....

What you want is to use variable parsing or [url=http://php.net/manual/en/language.operators.string.php]concatenation [php.net] strings like so

1. concatenation with double quotes
print "<form method='post' action='" . $_SERVER['PHP_SELF'] . "'><font size='2'>Organisational";
[Note that I do not need to escape single quotes within double quotes]

2.substitution with double quotes and an array
print "<form method='post' action='{$_SERVER['PHP_SELF']}'><font size='2'>Organisational";

3. substitution with a simple variable
$self = $_SERVER['PHP_SELF'];
print "<form method='post' action='$self'><font size='2'>Organisational";

4. concatenation with single quotes
print '<form method="post" action="' . $_SERVER['PHP_SELF'] . '"><font size="2">Organisational';