In a PHP window that includes an HTML table, how do you put the value of the PHP variable in a table cell?
PHP Variable in HTML Table Cell
Collapse
X
-
Tags: None
-
How DO you echo a variable in or out of a table cell
I got the value I need into a PHP variable with $uid = $_POST['uid'] and can echo the value of $uid to the window; now I want to put the value into an HTML table cell. Are you saying I should include value=<?php echo $uid ?> when defining the table cell? I do not under stand your phrase 'There's no difference in how you echo a variable in or out of a table cell' how DO you echo a variable in or out of a table cell?Comment
-
PHP doesn't care what you are creating, whether it's a HTML link, HTML table, HTML paragraph, XML elements, JavaScript code, or even things like binary strings. It's all just a bunch of text as far as PHP is concerned. You can put a echo statement wherever you want.
But, just to point one thing out. If you are putting PHP values originating from user input into a HTML page, be sure to run it through htmlentities first. Also, if the values are going into HTML element attributes (like the <input> value attribute), then surround them with quotes.
Code:// Potentially problematic and unsafe. <input value=<?php echo $variable; ?>> // Less problematic, but still unsafe. <input value="<?php echo $variable; ?>"> // Safe and not at all problematic. <input value="<?php echo htmlentities($variable, ENT_QUOTES, "UTF-8"); ?>">
Comment
Comment