Jump to content

Inserting HTML into a database


MortimerJazz

Recommended Posts

Hiya - I wasn't quite sure where to post this ...

I've designed a type of PM system. The idea is that a dynamically generated PM is sent to a user.

However, I'd like this PM to include clickable links and also format it with new lines etc.

So my question is, is it possible to store HTML in a MySQL database? When I've tried storing regular href's, I keep getting error messages on my page. Am I doing something wrong?

Thanks,
Link to comment
https://forums.phpfreaks.com/topic/36091-inserting-html-into-a-database/
Share on other sites

Thanks lilman.

The code's quite simple so far:

[code]
$message="The following person has expressed an interest in your toy:
<p>
Reference Number: <a href="http://www.mysite.com/viewtoy.php?toy=$ref
<p>
User: $username";


$sql = mysql_query("INSERT INTO prv_msg (sender, recipient,
        subject, message, sell_msg, date_sent, ip_sender)
        VALUES('$username', '$recipient', '$subject', '$message', '1', now(), '$ip')")
        or die (mysql_error());
[/code]
Try this

[code]$message="The following person has expressed an interest in your toy:
<p>
Reference Number: <a href=\"http://www.mysite.com/viewtoy.php?toy=$ref\"
<p>
User: $username";[/code]

I added \ in front of your quotation marks, if you don't PHP will assume that is the end of your statement when in act it is not. Give that a run and let me know if it works or not.
[quote author=lilman link=topic=124442.msg515593#msg515593 date=1170013916]
Try this

[code]$message="The following person has expressed an interest in your toy:
<p>
Reference Number: <a href=\"http://www.mysite.com/viewtoy.php?toy=$ref\"
<p>
User: $username";[/code]

I added \ in front of your quotation marks, if you don't PHP will assume that is the end of your statement when in act it is not. Give that a run and let me know if it works or not.
[/quote]

Could you achieve this easily with the addslashes function???
When assigning variables you cannot use quotes inside of the variable with out escaping them if you use quotes around the variable content (dunno if that made sense)...
So you could not assign the variable to htmlentities it... but if it was input by a user then you could...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.