Jump to content

[SOLVED] Returns In TextArea Field


twilitegxa

Recommended Posts

I'm sorry. I mean, I have the textarea as a field in a form that will be sent to a table in a database. Do I need to set some setting in the input tag to allow for these formatting types, or is that something I need to set in my field in my table?

Link to comment
Share on other sites

Still not exactly sure what your problem is. You want someone to be able to enter information in there and then output it so that the HTML code and everything looks exactly like it did when you entered the information?

 

If so, when you take information from the database, use nl2br() on it first to maintain the breaks and use htmlspecialchars() to make it so that html code is displayed rather than executed

Link to comment
Share on other sites

I am using the nl2br() on it, but I don't think it is maintaining the line breaks. Does it maintain them if they just press enter? That is what I want. This is what i have:

 

$biography = nl2br($posts_info['biography']);

Link to comment
Share on other sites

To allow HTML formatting, you don't do anything. When you output the content to the screen, the html tags in the text will automatically be rendered as HTML (as long as the mimetype of the document is text/html, which it should be for any html documents).

 

nl2br() will take any linebreaks (enter keys) and render them as html break tags. If it's not working, then you have a mistake somewhere. Show us your code.

Link to comment
Share on other sites

Here is the page that is displaying the profile:

 

<?php

session_start();

//Access Tracking Snippet

//set up static variables
$page_title = "showprofile.php";
$user_agent = getenv("HTTP_USER_AGENT");
$date_accessed = date("Y-m-d");

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
$db = mysql_select_db("smrpg", $conn) or die(mysql_error());

//create and issue query
$sql = "insert into access_tracker values
('', '$page_title', '$user_agent', '$date_accessed')";
mysql_query($sql,$conn);
?>

<?php
//check for required info from the query string
if (!$_GET['id']) {
header("Location: listcharacters.php");
exit;
}

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
mysql_select_db("smrpg", $conn) or die(mysql_error());

//verify the topic exists
$verify_topic = "select identity from scouts where
id = $_GET[id]";
$verify_topic_res = mysql_query($verify_topic, $conn)
or die(mysql_error());

if (mysql_num_rows($verify_topic_res) < 1) {
//this character does not exist
$display_block = "<p><em>You have selected an invalid character.
Please <a href=\"listcharacters.php\">try again</a></em></p>";
} else {
//gather rest of profile
$get_posts = "select *, date_format(create_time, '%b %e %Y at %r') as fmt_scout_create_time from scouts where id = $_GET[id]";

$get_posts_res = mysql_query($get_posts, $conn) or die(mysql_error());

//create the display string
$display_block = "
<table cellpadding=3 cellspacing=1 border=1>";

while ($posts_info = mysql_fetch_array($get_posts_res)) {
	$post_id = $posts_info['id'];
	$identity = nl2br(stripslashes($posts_info['identity']));
	$character_create_time = $posts_info['fmt_scout_create_time'];
	$username = $posts_info['username'];
	$biography = nl2br(stripslashes($posts_info['biography']));
	$name = $posts_info['name'];
	$element_of_influence = $posts_info['element_of_influence'];
	$age = $posts_info['age'];
	$birth_month = $posts_info['birth_month'];
	$birth_date = $posts_info['birth_date'];
	$birth_year = $posts_info['birth_year'];
	$height_feet = $posts_info['height_feet'];
	$height_inches = $posts_info['height_inches'];
	$blood_type = $posts_info['blood_type'];
	$hobbies = $posts_info['hobbies'];
	$favorite_color = $posts_info['favorite_color'];
	$favorite_gemstone = $posts_info['favorite_gemstone'];
	$favorite_food = $posts_info['favorite_food'];
	$least_favorite_food = $posts_info['least_favorite_food'];
	$favorite_school_subject = $posts_info['favorite_school_subject'];
	$least_favorite_school_subject = $posts_info['least_favorite_school_subject'];
	$strengths = $posts_info['strengths'];
	$weaknesses = $posts_info['weaknesses'];
	$goal = $posts_info['goal'];
	$mission = $posts_info['mission'];
	$biography = $posts_info['biography'];

	//add to display
	$display_block .= "
	<tr>
	<td width=24% valign=top><strong>Character Name:</strong></td>
	<td width=55% valign=top>$name</td>
	<td align=center valign=top rowspan=18><img src=\"image.gif\" height=\"500\" width=\"200\"></td>
	</tr>
	<tr>
	<td><strong>Element Of Influence:</strong></td>
	<td>$element_of_influence</td>
	</tr>
	<tr>
	<td><strong>Age:</strong></td>
	<td>$age</td>
	</tr>
	<tr>
	<td><strong>Date Of Birth:</strong></td>
	<td>$birth_month-$birth_date-$birth_year</td>
	</tr>
	<tr>
	<td><strong>Height:</strong></td>
	<td>$height_feet feet $height_inches inches</td>
	</tr>
	<tr>
	<td><strong>Blood Type:</strong></td>
	<td>$blood_type</td>
	</tr>
	<tr>
	<td><strong>Hobbies:</strong></td>
	<td>$hobbies</td>
	</tr><tr>
	<td><strong>Favorite Color:</strong></td>
	<td>$favorite_color</td>
	</tr>
	<tr>
	<td><strong>Favorite Gemstone:</strong></td>
	<td>$favorite_gemstone</td>
	</tr>
	<tr>
	<td><strong>Favorite Food:</strong></td>
	<td>$favorite_food</td>
	</tr>
	<tr>
	<td><strong>Least Favorite Food:</strong></td>
	<td>$least_favorite_food</td>
	</tr>
	<tr>
	<td><strong>Favorite School Subject:</strong></td>
	<td>$favorite_school_subject</td>
	</tr>
	<tr>
	<td><strong>Least Favorite School Subject:</strong></td>
	<td>$least_favorite_school_subject</td>
	</tr>
	<tr>
	<td><strong>Strengths:</strong></td>
	<td>$strengths</td>
	</tr>
	<tr>
	<td><strong>Weaknesses:</strong></td>
	<td>$weaknesses</td>
	</tr>
	<tr>
	<td><strong>Goal:</strong></td>
	<td>$goal</td>
	</tr>
	<tr>
	<td><strong>Mission:</strong></td>
	<td>$mission</td>
	</tr>
	<td><strong>Character Biography:</strong></td>
	<td>$biography</td>
	</tr>
	<tr>
	<td> </td>
	<td> </td>
	<td valign=left>Created By: $username<br>
	Created On: [$character_create_time]</td>
	</tr>";
	}

	//close up the table
	$display_block .= "</table>";
}
?>
<html>
<head>
<title><?php print $identity; ?>'s Profile</title>
<style type="text/css" media="screen">
/*<![CDATA[*/
@import url(global.css); 
/*]]>*/
</style>
</head>
<body>
<!-- HEADER -->
<h1 class="logo">Sailor Moon RPG</h1>
<!-- /HEADER -->
<?php include("topnav.php"); ?>
<div id="main">
<?php include("includes/log.php"); ?>
<?php include("mainnav.php"); ?>
<h1 align="center"><?php print $identity; ?></h1>
<?php print $display_block; ?>
</div>
<?php include("bottomnav.php"); ?><!-- FOOTER -->
<!-- FOOTER -->
<div id="footer_wrapper">
<div id="footer">
<p>Sailor Moon and all characters
are<br /> 
trademarks of Naoko Takeuchi.</p>
<p>Copyright © 2009 Liz Kula. All rights reserved.<br />
A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p>
<div id="foot-nav">
<ul>
<li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li>
<li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li>
</ul>
</div>
</div>
</div>
<!-- /FOOTER -->
</body>
</html>

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.