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
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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[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???
Link to comment
Share on other sites

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