j.g. Posted July 19, 2007 Share Posted July 19, 2007 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. Quote Link to comment Share on other sites More sharing options...
trq Posted July 19, 2007 Share Posted July 19, 2007 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. Quote Link to comment Share on other sites More sharing options...
j.g. Posted July 19, 2007 Author Share Posted July 19, 2007 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. Quote Link to comment Share on other sites More sharing options...
j.g. Posted July 19, 2007 Author Share Posted July 19, 2007 I tried the following, but am not seeing an difference: echo (nl2br($r["title"])); Anyone have the correct way to do it? -jg Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 19, 2007 Share Posted July 19, 2007 I tried the following, but am not seeing an difference: echo (nl2br($r["title"])); Anyone have the correct way to do it? -jg Maybe title is one line (or one string with no line breaks). Quote Link to comment 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.