how can i echo this code. when i echo it it prints out the html tags and <? php code ?> i want to echo the html code and interpret the php as php.

echo "<h2>Add Contact</h2>
	<form name=\"form1\" action=\"<?=$_SERVER[\'PHP_SELF\'];?>?mode=added\" method=\"post\">
	<table class=\"tableStyleClassTwo\">
	<tr><td>Name:</td><td><div align=\"left\">
	<input type=\"text\" name=\"name\" />
	</div></td></tr>
	<tr><td>Phone:</td><td><div align=\"left\">
	<input type=\"text\" name=\"phone\" />
	</div></td></tr>
	<tr><td>Email:</td><td><div align=\"left\">
	<input type=\"text\" name=\"email\" />
	</div></td></tr>
	<tr><td colspan=\"2\" align=\"center\"><a href=\"javascript:history.go(-1);\">Back</a> | <input name=\"Submit\" type=\"submit\" id=			\"Submit\" value=\"Add New Contact\" <?php if($disable ==1){?>disabled<?php } ?>/></td></tr>
	<input type=\"hidden\" name=\"mode\" value=\"added\">
	</table>
	</form>";

Recommended Answers

All 5 Replies

First of all, you don`t need to put the <?php and ?> tags in echo.
Second of all, try replacing " with '
If it won`t work, you need to separate the html strings for the php using: .

so basically someithin like this, but when i put the "." in front of the <? it still doesnt work?

echo'
	<h2>Add Contact</h2>
	<form name="form1" action=".<?=$_SERVER[\'PHP_SELF\'];?>?mode=added" method="post">';

so basically someithin like this, but when i put the "." in front of the <? it still doesnt work?

echo'
	<h2>Add Contact</h2>
	<form name="form1" action=".<?=$_SERVER[\'PHP_SELF\'];?>?mode=added" method="post">';

why you are using still php tag in echo
remove first...write like this.

<form name="form1" action=".$_SERVER[\'PHP_SELF\']."?mode=added" method="post">';

after removing <? ?> tags then use htmlentities function to output html code on browser.

echo htmlentities("your html string");

u dont put <?php and ?> in php variables.
you have to insert a variable like the person above stated

<?php echo $variable; ?>
<?php echo "my variable is ".$variable; ?>
or
<?php echo "my variable is $variable; ?> sometimes works.
and then u can do it this way:
<?php echo "my variable is ".$variable."."; ?>
which is the one u should use because u dont end the echo with the $variable

some people told me that u have to have spaces when u insert a variable like this:

<?php echo "my variable is " . $variable . " but i hate echoing my variable this way"; ?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.