I use a form to write an article and then save it into the mysql table.
I use this to save it:
$Db_profile = safe_sql($_POST['x_profile']);
and the function safe_sql is: - // Make variable SQL safe
-
function safe_sql( $value )
-
{
-
$value = strip_tags(trim($value));
-
-
// Stripslashes
-
if (get_magic_quotes_gpc()) {
-
$value = stripslashes($value);
-
}
-
// Quote if not integer
-
if (!is_numeric($value)) {
-
$value = mysql_real_escape_string($value);
-
}
-
return $value;
-
} // End of Function
-
I save it with a normal insert: -
$sql = "UPDATE clients SET
-
profile = '$Db_profile',
-
last_date = '$today'
-
-
WHERE user_id = \"{$_SESSION['expert']}\" ";
-
-
mysql_query($sql) or die("could not execute PROFILE update query". mysql_error());
-
When I come to display the article all the sentences just get pushed together,the line breaks have al gone.
I use this to display it: - <div class="hot04">
-
<p><?php echo "$profile"; ?></p>
-
</div> <!-- End div:hot04 -->
-
The strange thing is, when I look at the table data it still contains the line breaks so it must be my display method that is causing the problem.
What am I doing wrong ?
10 1802
HTML won't take a newline character (\n) and create a new line with it - it will in the source code, but not the live code. You need to convert these into a html tag (<br />). Luckily, there is a standard PHP function that does this for you ( nl2br()). Just simply use this function on your output. -
-
$text = "These\n will\n appear\n on\n new\n lines";
-
-
echo nl2br($text);
-
-
Hi Marcus,
Thanks,
So I can just do:
<p><?php echo "nl2br($profile)"; ?></p>
or maybe a 2 step would be better
$Sh_profile = nl2br($profile);
later
<p><?php echo "$Sh_profile"; ?></p>
Do I need the double quotes ?
( I am never quite sure )
the first code won't work because of the quotation marks (PHP doesn't look for functions in a string)
in the third code you can omit the quotation marks, because all you want to print is the variable.
which of the two ways you implement depends on your personal liking. @jeddiki
If you're not sure about something, refer to the PHP manual, it usually gives good explanation and plenty of examples. PHP: echo - Manual
Markus (with a K) ;]
Double quotes: functions will not be parsed inside them, variables, however, will be parsed.
So, the second option you show will work.
note:
only works, if the function has a (printable) return value.
Thanks for your help,
So it seems that the textarea and the mysql dtatbase both like
the line break /n/r style and will record them invisibly,
but the HTML page needs to have these output converted <br> or <br />
One more this that is confusing me.
When using the texarea to write an article how can I add bold
and italics so that they will save in the database and then
display correctly when I output them to an HTML page ?
@jeddiki
probably the best is to add some tags, that will be converted to the appropriate HTML tags (be it <span>, <b> or <i>). make sure you sanitize your input before putting it to DB or the HTML page.
@Markus
note: PHP provides an extension to parse BBCode.
Thanks, I am checking out how I can get the bbCode extension for my server.
Looks like what I need :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: The Roys |
last post by:
Hi
I have a textbox which displays a formatted numeric. eg: 100,000
When I retreive this value for calculations, it is valued at 100
eg:
calc = val(txtbox) * 2
calc will equal 200, not...
|
by: George |
last post by:
I've got an interesting problem that I just have not been able to
figure out. I'm trying to use Mail_Mime to send multi-part/mixed
emails from a Linux server and I am having trouble getting...
|
by: sck10 |
last post by:
Hello,
I am pulling data from a SQL Server table. One field that is (varchar 4000)
is used to show notes. I am using a FormView for showing and editing the
data. When the form is in Item...
|
by: Griff |
last post by:
I want to display a repeating set of formatted infomation that appears
within a "box" so that the individual boxes appear to the right of the
previous one until the line is filled and then the next...
|
by: biganthony via AccessMonster.com |
last post by:
Hi,
I decided to install Office 2003 Service Pack 3 on my home computer to test
(in full knowledge that there may be some issues with it). After installation,
I have noticed that with a small...
|
by: suprodeep |
last post by:
have a page for admin(admin.aspx). This would enter product name, image, category name and and long description in a formatted manner. The prod name, image, category name can be inputted to...
|
by: Kumba |
last post by:
Hi all,
Working on a pretty fancy access report that prints out a schedule of events in a two-column format, I've stumbled across the need for displaying formatted text into a field. Since I'm...
|
by: Andy B |
last post by:
I have the object property StockContract.Dictionary which is a dictionary
collection of <string, stringkey/value pairs. I need to be able to
retreive the keys and their values and display them on a...
|
by: Bobby |
last post by:
Hi,
I'm using Office 2007. I have a text field called txtDate which is
formatted to medium date. This gives me the date picker when the
control has the focus.
I have several other text controls...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |