jeaker Posted May 3, 2007 Share Posted May 3, 2007 I have a text field and I want it to make a new like when the user presses enter. What I mean by that is, I have a text field that is populated by info from my database. This information can be edited by the admin. The admin then submits the revesions by clicking update. Is it possible to have the test are recognize the new lines? Here is my code for the text area... <form method="post" action="admin_home.php"> <input type="hidden" name="id" value="1"> <table border="0" cellpadding="2" cellspacing="1" class="box" align="center"> <tr> <td>Title</td> <td><input name="title" type="text" class="box" id="title" value="<?=$title;?>"></td> </tr> <tr> <td>Content</td> <td><textarea name="content" cols="50" rows="10" class="box" id="content"><?=$content;?></textarea></td> </tr> <tr> <td width="100"> </td> <td> </td> </tr> <tr> <td colspan="2" align="center"><input name="update" type="submit" class="box" id="update" value="Update Home Page"></td> </tr> </table> </form> and here is the admin_home.php... <?php include 'library/config.php'; include 'library/opendb.php'; if(isset($_GET['id'])) { $query = "SELECT id, title, content ". "FROM home ". "WHERE id = '{$_GET['id']}'"; $result = mysql_query($query) or die('Error : ' . mysql_error()); list($id, $title, $content) = mysql_fetch_array($result, MYSQL_NUM); $content = htmlspecialchars($content); } else if(isset($_POST['title'])) { $id = $_POST['id']; $title = $_POST['title']; $content = $_POST['content']; if(!get_magic_quotes_gpc()) { $title = addslashes($title); $content = addslashes($content); } // update the article in the database $query = "UPDATE home ". "SET title = '$title', content = '$content' ". "WHERE id = '$id'"; mysql_query($query) or die('Error : ' . mysql_error()); // then remove the cached file $cacheDir = dirname(__FILE__) . '/cache/'; $cacheFile = $cacheDir . '_' . $_GET['id'] . '.html'; @unlink($cacheFile); // and remove the index.html too because the file list // is changed @unlink($cacheDir . 'index.html'); echo "<p align='center'>You have Successfully Updated the Home Page.</p>"; // now we will display $title & content // so strip out any slashes $title = stripslashes($title); $content = stripslashes($content); } include 'library/closedb.php'; ?> If anyone has any ideas, please let me know. Thanks in advance for all the help. You guys are great! Link to comment https://forums.phpfreaks.com/topic/49750-solved-help-with-making-a-new-line/ Share on other sites More sharing options...
corbin Posted May 3, 2007 Share Posted May 3, 2007 I think nl2br() is what you're looking for.... Link to comment https://forums.phpfreaks.com/topic/49750-solved-help-with-making-a-new-line/#findComment-244008 Share on other sites More sharing options...
jeaker Posted May 3, 2007 Author Share Posted May 3, 2007 I have read alot about that by googleing that.What I don't understand is where it would go? Link to comment https://forums.phpfreaks.com/topic/49750-solved-help-with-making-a-new-line/#findComment-244010 Share on other sites More sharing options...
trq Posted May 3, 2007 Share Posted May 3, 2007 It wouldn't go in either of those pages. When you finally display this data (or at any time you display it outside a form) you use nl2br. Link to comment https://forums.phpfreaks.com/topic/49750-solved-help-with-making-a-new-line/#findComment-244018 Share on other sites More sharing options...
jeaker Posted May 3, 2007 Author Share Posted May 3, 2007 O, I am putting the data back out via another page. The code on that page looks like this... <body> <?php include 'library/config.php'; include 'library/opendb.php'; $result = mysql_query("SELECT * FROM home"); while($row = mysql_fetch_array($result)) { ?> <div class="content"> <h1><?php echo $row['title']; ?></h1> <br><br> <p><?php echo $row['content']; ?></p> <br> <?php } ?> I apologize if I am a little slow. I am still fairly new to PHP. Is there any particle place in this code to put the nl2br? Link to comment https://forums.phpfreaks.com/topic/49750-solved-help-with-making-a-new-line/#findComment-244023 Share on other sites More sharing options...
trq Posted May 3, 2007 Share Posted May 3, 2007 <p><?php echo nl2br($row['content']); ?></p> Link to comment https://forums.phpfreaks.com/topic/49750-solved-help-with-making-a-new-line/#findComment-244028 Share on other sites More sharing options...
jeaker Posted May 3, 2007 Author Share Posted May 3, 2007 NIce, Thanks to both of you guys for your help!!! Link to comment https://forums.phpfreaks.com/topic/49750-solved-help-with-making-a-new-line/#findComment-244050 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.