Jump to content

Newbie ? - Help using nl2br


j.g.

Recommended Posts

Hello Board!

 

I'm trying to implement a text box that will not require HTML, but will store the input into a mysql db with html tags; I think I can do this with the nl2br function - however, I'm not sure on what I need to do to get this to work.  I've tried a couple of different implementations with no success to this point.  :-\  So, here I am - asking the experts!!

 

The input is being input into a text box:

 

<td>
  <textarea rows="5" cols="34" name="title"><?php echo $title;?></textarea>
</td>

 

And input into my db (through either an INSERT or UPDATE stmt):

 

if ( $operation == "Add" && !$error_msg)
{
   if($url == "offsite")
   {
$url = $offsite_url;
$offsite_link = 1;
   }
   
   $query = "INSERT INTO announcements (title, url, announcement_type_id, offsite_link, post_date) "
                 ."VALUES('".$db->clean($title)."', '".$db->clean($url)."', '".$db->clean($type_id)."', '"
                 .".$db->clean($offsite_link)."', now() )";

   $result = $db->query($query) or die("Invalid Query - announcements Add");
   $announcement_id = $db->get_last_insert_id();

   header("Location: announcements_updater.php?type_id=".$type_id);
}		
elseif ( $announcement_id && $operation == "Update" && !$error_msg )
{

   if($url == "offsite")
   {
$url = $offsite_url;
$offsite_link = 1;
   }

   $query = "UPDATE announcements SET title = '".$db->clean($title)."', url = '".$db->clean($url)."', "
                ."offsite_link = '".$db->clean($offsite_link)."', last_update = now() "
                ."WHERE announcement_id = '".$db->clean($announcement_id)."'";

   $result = $db->query($query) or die("Invalid Query - announcements Update");

   header("Location: announcements_updater.php?type_id=".$type_id);

}

 

So, I don't want to require the user's to input HTML into the text box, however, I want to store it as HTML in the db and be able to retrieve it as HTML for display purposes...

 

 

Thanks in advance for your time and expertise!! Please let me know if I can provide anymore information.

 

Thanks much,

-j.g.

Link to comment
https://forums.phpfreaks.com/topic/60811-newbie-help-using-nl2br/
Share on other sites

So, I don't want to require the user's to input HTML into the text box, however, I want to store it as HTML in the db and be able to retrieve it as HTML for display purposes...

 

I would not recommend storing html within your database. Keep your data in its raw format then use nl2br on it when you pull it out for display.

I guess I'm OK with that - I'm the Newbie here and am just following the way things were done before and I see the tags in the db when I query it....

 

 

OK, so this is where I'm posting the data in the header:

<tr>
<td style="padding:10px;" class="smtext">
    <?php
         $query = "SELECT title, announcement_type_id FROM announcements "
                      ."WHERE announcement_type_id = '0' "
                      ."ORDER BY title";
 $result = $db->query($query) or die("Invalid Query - Announcements Select");
		      
 while( $r = $db->fetch_row($result) )
 {
    ?>
   <li>
   <?php
        echo ($r["title"]);
        echo "<BR>";
          }	
   ?>
   </li>
   <p></td>

 

 

Can I still use nl2br here?  And if so, how can I do that?

 

Thanks!

-j.g.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.