Jump to content
RMZ

Textarea value not displaying

Recommended Posts

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 by cyberRobot
Added a more meaningful post title

Share this post


Link to post
Share on other sites

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.

  • Like 1

Share this post


Link to post
Share on other sites

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>

Share this post


Link to post
Share on other sites

Jacobseated,

The code was written sometime in 2013...... if that classifies as old-fashioned :)

 

  • Like 1

Share this post


Link to post
Share on other sites

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.