Jump to content

[SOLVED] help with making a new line?


jeaker

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.