Jump to content

Recommended Posts

<?php session_start(); ?>
<style>
a {
color:black;
font-weight:bold;
}

holder {
width:600px;
}

table {
width:600px;
}
</style>
<?php
$session = $_SESSION['user'];
$thread = $_GET['thread'];

mysql_connect($mysql_host, $mysql_user, $mysql_password);
mysql_select_db($mysql_database);

$get_thread_exist = mysql_query("SELECT COUNT(id) FROM topics WHERE id='$id'");
$reply = $_POST['message'];
$reply = mysql_real_escape_string($reply);
$thread_post = $_POST['hidden'];
$ip = $_SERVER['REMOTE_ADDR'];
$date = date("M-D-Y");

$get_thread_lock = mysql_query("SELECT locked FROM topics WHERE id='$id'");
$locked = mysql_fetch_assoc($get_thread_lock);

$before = array("\r\n", "\n", "\r");
$after = array("<br/>", "<br/>", "<br/>");
$message_spaces =  nl2br($reply);
if(!$session)
{
  
	echo "<center><div class='holder'><table border='1'><tr><td><center>Sorry, you must be logged in to access this page! <a href='index.php'>Home</a></center> <br/></td></tr></table></div></center>";
}
elseif(!$thread && !$thread_post)
{
	echo "". $locked ."<center><div class='holder'><table border='1'><tr><td><center>You haven't selected a thread to reply to! <a href='index.php'>Home</a></center> <br/></td></tr></table></div></center>";
}
elseif(!$get_thread_exist)
{
	echo "<center><div class='holder'><table border='1'><tr><td><center>You are trying to reply to a thread that doesn't exist! <a href='index.php'>Home</a></center> <br/></td></tr></table></div></center>";
}
elseif($locked['locked'] == 1)
{
	echo "<center><div class='holder'><table border='1'><tr><td><center>This topic is locked! <a href='viewtopic.php?id=". $id ."'>Back to topic</a></center> <br/></td></tr></table></div></center>";
}
elseif(!$reply)
{
 echo "<center><div class='holder'><table border='1'><tr><td><center><form action='reply.php' method='POST'><br/>Message: <br/><textarea name='message' rows='20' cols='35' maxlength='3000'></textarea><br/><br/> <input type='hidden' value='". $thread ."' name='hidden'><input type='submit' value='Submit Post'></form></center> <br/></td></tr></table></div></center>";
}
elseif(strlen($reply) >= 15)
{
	mysql_query("INSERT INTO posts VALUES ('', '$ip', '$date', '$session', '$message_spaces', '$thread_post')");
	mysql_query("UPDATE users SET postcount = postcount + 1 WHERE username='$session'");
	mysql_query("UPDATE topics SET replies = replies + 1 WHERE  id='$thread_post'");
  echo "<center><div class='holder'><table border='1'><tr><td><center>Your post has been posted! <a href='viewtopic.php?id=". $thread_post ."'>Go back to thread</a>.</center> <br/></td></tr></table></div></center>";
}
else
{
 echo "<center><div class='holder'><table border='1'><tr><td><center>Sorry, you need to have at least 15 characters in your post!</center> <br/></td></tr></table></div></center>";
}


?>

 

And I can't view the source, my website host doesn't display the part that shows the messages.

Link to comment
https://forums.phpfreaks.com/topic/206778-not-replacing-reply/#findComment-1081408
Share on other sites

You lost me there a little bit. If it gets sent to the browser, you should be able to view the html page source via the menu View --> Page Source, or something similar. However, that doesn't really matter at this point. The question I have is: are you trying to replace line feeds/new lines with spaces or html line breaks?

Link to comment
https://forums.phpfreaks.com/topic/206778-not-replacing-reply/#findComment-1081413
Share on other sites

I think you might be conflating an html line break (<br />) with a space.

 

If you replace \r, \n, or \r\n with <br />'s, it will still display the same in the browser. If I were to type into  a <textarea> :

 

I am\n

the one\n

\n

and only.\n

 

Then replace the \n new lines with <br />'s it would still be rendered by the browser as

 

I am

the one

 

and only.

 

Unless I'm completely misreading your posts, I think what you want is more along the lines of this to change new lines and CRs to spaces.

 

$before = array("\r\n", "\n", "\r");
$message_spaces = str_replace($before, ' ', $reply);

Link to comment
https://forums.phpfreaks.com/topic/206778-not-replacing-reply/#findComment-1081425
Share on other sites

I looked at the code you posted and don't see where you're displaying the message. You're storing it in the database, but not displaying it.

 

The nl2br function should be used when displaying the content, not when storing the content.

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/206778-not-replacing-reply/#findComment-1081428
Share on other sites

No.....I want it so when someone presses enter a new LINE is made.....

 

I wasn't trying to be difficult, but you were saying you wanted one thing, then providing an example of something different. It's always best to clarify what someone actually wants before you try to give an answer . . .

Link to comment
https://forums.phpfreaks.com/topic/206778-not-replacing-reply/#findComment-1081461
Share on other sites

I looked at the code you posted and don't see where you're displaying the message. You're storing it in the database, but not displaying it.

 

The nl2br function should be used when displaying the content, not when storing the content.

 

Ken

 

So I should switch back to my original code? And why doesn't it work either?

Link to comment
https://forums.phpfreaks.com/topic/206778-not-replacing-reply/#findComment-1081646
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.