Jump to content

How to echo the value php variable?


astheo

Recommended Posts

Hi..How do I echo the value of the php variable which is located inside an echo tag? Here's a portion of my code to make my point clearer.

 

There are two ways I know:

1st,

$String = $_POST["message"];

echo '<table><tr><td> ."$String". </td></tr></table>';

 

2nd,

$String = $_POST["message"];

echo '<table><tr><td> .'$String'. </td></tr></table>';

 

The value of the $String variable is what I want to echo together with the table. But both display the variable name itself instead of the value. I'd like someone with good heart to help me out with this little trouble. Thanks!

Link to comment
Share on other sites

try this

 

$String = $_POST["message"];

echo '<table><tr><td>'.$String.'</td></tr></table>';

 

Hi, thanks but it didn't make any difference at all...I still get the same output...

 

are you sure you did it right?

because thats the correct format to do it.

 

yes i did. if you want, i will post the whole code here so you'll see and help me where to point out the error? it's just 20-30 lines of code...if you want...

 

Link to comment
Share on other sites

<html>

<body>

 

<?php

    $feedback = $_POST["comment"];

    $name = $_POST["author"];

   

    echo '<html><head>

<title>Mobile Phone Tweaks</title>

</head>

<style type="text/css">

.ent {font-family: verdana, tahoma; font-size: 10px;}

.ek {filter: alpha(opacity="70"); background-color="none"; border: 0px solid;}

a:link {  text-decoration: none}

a:active {  text-decoration: none}

a:visited {  text-decoration: none}

</style>

 

<div align="center">

<table style="border: 1px dotted #FFFFFF" cellpadding="15" cellspacing="1" border="0" bordercolor="#4B7EC5" class="ek"  width="806" bgcolor="lightgray">

<tr>

<td>

<h3>Comments:</h3><br><cite>.'$name'. </cite> Says:<br><br><div align="center"><table border="0" width="700"  ><tr><td><p>.'$feedback'.</p><br><br></td></tr></table></div>

<h4 class="comments">Leave a Reply</h4>

 

<form action="comment.php" method="post" id="commentform">

 

 

<p><input type="text" name="author" id="author" value="" size="22" tabindex="1" />

<label for="author"><small>Name (required)</small></label></p>

 

<p><input type="text" name="email" id="email" value="" size="22" tabindex="2" />

 

<label for="email"><small>Mail (will not be published) (required)</small></label></p>

 

<p><input type="text" name="url" id="url" value="" size="22" tabindex="3" />

<label for="url"><small>Website</small></label></p>

 

 

 

 

<p><textarea name="comment" id="comment" cols="70%" rows="10" tabindex="4"></textarea></p>

 

<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />

<input type="hidden" name="comment_post_ID" value="143" />

</p>

 

</td>

</form>

 

</tr>

</table>

</div>

 

</html>

';

    ?>

 

</body>

</html>

 

 

 

 

it's a bit crowded coz i just made it...the red colored texts are the ones you suggested. Thanks! :)

Link to comment
Share on other sites


<?php
     $feedback = $_POST["comment"];
     $name = $_POST["author"];
     
     echo '<html><head>
<title>Mobile Phone Tweaks</title>
</head>
<style type="text/css">
.ent {font-family: verdana, tahoma; font-size: 10px;}
.ek {filter: alpha(opacity="70"); background-color="none"; border: 0px solid;}
a:link {  text-decoration: none}
a:active {  text-decoration: none}
a:visited {  text-decoration: none}
</style>

<div align="center">
<table style="border: 1px dotted #FFFFFF" cellpadding="15" cellspacing="1" border="0" bordercolor="#4B7EC5" class="ek"  width="806" bgcolor="lightgray">
<tr>
<td>
<h3>Comments:</h3>
<cite>'. $name .' </cite> Says:

<div align="center"><table border="0" width="700"  ><tr><td><p>'. $feedback .'</p>

</td></tr></table></div>
<h4 class="comments">Leave a Reply</h4>

<form action="comment.php" method="post" id="commentform">


<p><input type="text" name="author" id="author" value="" size="22" tabindex="1" />
<label for="author"><small>Name (required)</small></label></p>

<p><input type="text" name="email" id="email" value="" size="22" tabindex="2" />

<label for="email"><small>Mail (will not be published) (required)</small></label></p>

<p><input type="text" name="url" id="url" value="" size="22" tabindex="3" />
<label for="url"><small>Website</small></label></p>




<p><textarea name="comment" id="comment" cols="70%" rows="10" tabindex="4"></textarea></p>

<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
<input type="hidden" name="comment_post_ID" value="143" />
</p>

</td>
</form>

</tr>
</table>
</div>

</html>
';
     ?>

</body>
</html>


Link to comment
Share on other sites

You have so much plain HTML in that echo statement, just leave PHP and echo the two variables individually:

<html>
<?php
     $feedback = $_POST["comment"];
     $name = $_POST["author"];
?>
<head>
<title>Mobile Phone Tweaks</title>
</head>
<style type="text/css">
.ent {font-family: verdana, tahoma; font-size: 10px;}
.ek {filter: alpha(opacity="70"); background-color="none"; border: 0px solid;}
a:link {  text-decoration: none}
a:active {  text-decoration: none}
a:visited {  text-decoration: none}
</style>
<body>
<div align="center">
<table style="border: 1px dotted #FFFFFF" cellpadding="15" cellspacing="1" border="0" bordercolor="#4B7EC5" class="ek"  width="806" bgcolor="lightgray">
<tr>
<td>
<h3>Comments:</h3>
<cite><?php echo $name; ?></cite> Says:

<div align="center"><table border="0" width="700"  ><tr><td><p><?php echo $feedback; ?></p>

</td></tr></table></div>
<h4 class="comments">Leave a Reply</h4>

<form action="comment.php" method="post" id="commentform">


<p><input type="text" name="author" id="author" value="" size="22" tabindex="1" />
<label for="author"><small>Name (required)</small></label></p>

<p><input type="text" name="email" id="email" value="" size="22" tabindex="2" />

<label for="email"><small>Mail (will not be published) (required)</small></label></p>

<p><input type="text" name="url" id="url" value="" size="22" tabindex="3" />
<label for="url"><small>Website</small></label></p>




<p><textarea name="comment" id="comment" cols="70%" rows="10" tabindex="4"></textarea></p>

<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
<input type="hidden" name="comment_post_ID" value="143" />
</p>

</td>
</form>

</tr>
</table>
</div>
</body>
</html>

 

Also, your HTML code was malformed, which I fixed. If you're going to use PHP to manipulate your HTML, learn how to write correct HTML.

 

Ken

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.