Jump to content

Recommended Posts

I am working on creating a post that will replace all carriage returns with a <br /> tag so the format the user entered will be preserved.

 

here is the code I am using for my create_post() and the str_replace() for replacing carraige returns.

 

$body = str_replace("\r","<br />",$_POST['txt']);

/************************************************************************/
  function create_post($params)
  {
    $connection = db_connect();
$body;
    $query = sprintf("INSERT INTO comtable SET
                          title = '%s',
                          name = '%s',
                          txt = '%s',
                          email = '%s',
                          time = NOW(),
                          user_id = '%s'",
                          mysql_real_escape_string($params['title']),
                          mysql_real_escape_string($params['name']),
                          mysql_real_escape_string($params['txt']),
                          mysql_real_escape_string($params['email']),
                          mysql_real_escape_string($params['time']),
                          mysql_real_escape_string($params['user_id']));
    $result = mysql_query($query);
    if (!$result) return false;
    else return true;
  }

 

here is my post page for displaying the database results:

 

<?php include_once('model/post.php'); ?>
<table width="400" border="1">
<tr>
<td>
<h2><?php echo $post['title']; ?></h2>
</td>
</tr>

<tr>
<td>
name: <?php echo '<a href="'.$post['email'].'">'.$post['name'].'</a>'; ?>

<!--date created: <?php echo $hr.':'.$min.' '.$timetype.' '. $mo.'/'.$da.'/'.$yr; ?>-->

post id: <?php echo $post['post_id']; ?>
</td>
</tr>

<tr>
<td>
comment: <br/> <?php echo $body; ?>
</td>
</tr>
</table>

 

The file included is the one containing the create_post() and $body. It seems to me right now I am not getting any database data in $body, just the function to replace the returns with <br />. The form that is getting this data and the returns from the user is below:

 

    <textarea cols="40" name="post[txt]" rows="5"></textarea>

 

obviously there is more, but this is the relvent part.

 

The method of the form is set to "post"

 

I appreciate the help

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.