RMZ Posted November 20, 2019 Share Posted November 20, 2019 (edited) Hi All, New to PHP so any help appreciated Can anyone explain why this; <tr><td><label for="notes">Notes:</label> <td><input type="text" id="notes" name="notes" maxlength="250" size="70" value="<?php if (!empty($notes)) echo $notes; ?>"></input></td> </tr> Displays data from a MySQL database (field $notes, VARCHAR(250) ) and this; <tr><td class=textboxlabel><label for="notes">Notes:</label> <td><textarea id="notes" name="notes" rows="4" cols="70" maxlength="250" value="<?php if (!empty($notes)) echo $notes; ?>"></textarea></td> </tr> displays nothing???? Not sure how much info to provide........ Edited November 20, 2019 by cyberRobot Added a more meaningful post title Quote Link to comment https://forums.phpfreaks.com/topic/309557-textarea-value-not-displaying/ Share on other sites More sharing options...
cyberRobot Posted November 20, 2019 Share Posted November 20, 2019 Textarea doesn't use the value attribute. Place the value between the open and close textarea tags instead. More information can be found here:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea Quote Link to comment https://forums.phpfreaks.com/topic/309557-textarea-value-not-displaying/#findComment-1571736 Share on other sites More sharing options...
JacobSeated Posted November 20, 2019 Share Posted November 20, 2019 Also, escaping in and out of HTML like this is kinda old fashioned. These days you may want to keep your HTML separate from PHP. Personally I limit myself to placing only variables in my HTML. So, no conditional logic in the HTML itself, which makes it very clean and easy to maintain. If using heredoc, you can use curly brackets around variables. I.e.: $tpl_content = array('title' => 'test', 'article_body' => 'hallo world'); $template = <<<_TEMPLATE_ <!doctype html> <html> <head> <title>{$tpl_content['title']}</title> </head> <body> <article> <header> <h1>{$tpl_content['title']}</h1> </header> {$tpl_content['article_body']} </article> </body> </html> _TEMPLATE_; // End of Template I wish I had learned this early on myself, as it could have saved me many hours of spaghetti hell. 1 Quote Link to comment https://forums.phpfreaks.com/topic/309557-textarea-value-not-displaying/#findComment-1571737 Share on other sites More sharing options...
RMZ Posted November 20, 2019 Author Share Posted November 20, 2019 Thanks cyberRobot This now does what's required <tr><td class=textboxlabel><label for="notes">Notes:</label> <td><textarea id="notes" name="notes" rows="4" cols="70" maxlength="250" > <?php if (!empty($notes)) echo $notes; ?> </textarea></td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/309557-textarea-value-not-displaying/#findComment-1571738 Share on other sites More sharing options...
cyberRobot Posted November 20, 2019 Share Posted November 20, 2019 No problem 😊 Quote Link to comment https://forums.phpfreaks.com/topic/309557-textarea-value-not-displaying/#findComment-1571739 Share on other sites More sharing options...
RMZ Posted November 20, 2019 Author Share Posted November 20, 2019 Jacobseated, The code was written sometime in 2013...... if that classifies as old-fashioned 1 Quote Link to comment https://forums.phpfreaks.com/topic/309557-textarea-value-not-displaying/#findComment-1571740 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.