astheo Posted March 6, 2008 Share Posted March 6, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/94626-how-to-echo-the-value-php-variable/ Share on other sites More sharing options...
ohdang888 Posted March 6, 2008 Share Posted March 6, 2008 try this $String = $_POST["message"]; echo '<table><tr><td>'.$String.'</td></tr></table>'; Quote Link to comment https://forums.phpfreaks.com/topic/94626-how-to-echo-the-value-php-variable/#findComment-484524 Share on other sites More sharing options...
astheo Posted March 6, 2008 Author Share Posted March 6, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/94626-how-to-echo-the-value-php-variable/#findComment-484536 Share on other sites More sharing options...
ohdang888 Posted March 6, 2008 Share Posted March 6, 2008 $String = $_POST["message"]; echo '<table><tr><td>'; echo $String; echo '</td></tr></table>'; Quote Link to comment https://forums.phpfreaks.com/topic/94626-how-to-echo-the-value-php-variable/#findComment-484544 Share on other sites More sharing options...
Northern Flame Posted March 6, 2008 Share Posted March 6, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/94626-how-to-echo-the-value-php-variable/#findComment-484555 Share on other sites More sharing options...
aximbigfan Posted March 6, 2008 Share Posted March 6, 2008 I just do echo "<p>$string</p>"; Don't put " or ' around the var. If you want, you can put { and } around the string though. Chris Quote Link to comment https://forums.phpfreaks.com/topic/94626-how-to-echo-the-value-php-variable/#findComment-484585 Share on other sites More sharing options...
Lamez Posted March 6, 2008 Share Posted March 6, 2008 ya I do this $value = $_POST['value']; echo "This is my value: $value"; Quote Link to comment https://forums.phpfreaks.com/topic/94626-how-to-echo-the-value-php-variable/#findComment-484588 Share on other sites More sharing options...
astheo Posted March 6, 2008 Author Share Posted March 6, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/94626-how-to-echo-the-value-php-variable/#findComment-484606 Share on other sites More sharing options...
Northern Flame Posted March 6, 2008 Share Posted March 6, 2008 yea post the whole thing Quote Link to comment https://forums.phpfreaks.com/topic/94626-how-to-echo-the-value-php-variable/#findComment-484621 Share on other sites More sharing options...
astheo Posted March 6, 2008 Author Share Posted March 6, 2008 <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! Quote Link to comment https://forums.phpfreaks.com/topic/94626-how-to-echo-the-value-php-variable/#findComment-484623 Share on other sites More sharing options...
Northern Flame Posted March 6, 2008 Share Posted March 6, 2008 <?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> Quote Link to comment https://forums.phpfreaks.com/topic/94626-how-to-echo-the-value-php-variable/#findComment-484629 Share on other sites More sharing options...
ohdang888 Posted March 6, 2008 Share Posted March 6, 2008 get rid of those spaces in between the ' and the . make it this blah'.$feeback.'blahdsfdsfas Quote Link to comment https://forums.phpfreaks.com/topic/94626-how-to-echo-the-value-php-variable/#findComment-485428 Share on other sites More sharing options...
kenrbnsn Posted March 6, 2008 Share Posted March 6, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/94626-how-to-echo-the-value-php-variable/#findComment-485446 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.