0

I've searched on here and can not find the right answer, but then I might be asking for too much. I have a form (that i upload as admin) to update a users description and include some special characters etc see below. This is the php code when updating the database.

$conn = getConnection();
$conn->osc_dbExec(sprintf("UPDATE %st_editable SET s_heading = '%s' WHERE content_id =   '%d'", DB_TABLE_PREFIX, $s_heading,$id));
$conn->osc_dbExec(sprintf("UPDATE %st_editable SET s_message = '%s' WHERE content_id = '%d'", DB_TABLE_PREFIX, $s_message,$id));
$conn->osc_dbExec(sprintf("UPDATE %st_editable SET resume = '%s' WHERE content_id = '%d'", DB_TABLE_PREFIX,($resume),$id));

Wont bother you guys with the rest of the code because its dealing with peoples if statements that work fine. The form i use is simple text editor and is

<tr>
<td valign=top>Description:</td>
<td><textarea cols=45 rows=6 name=resume><?php echo $detail['resume']; ?><?=$a1[resume]?></textarea></td>

My question is if i type this into the description, i need it to go into the database exactly so i can then output it exactly. eg

<strong>YOUR DETAILS</strong>
<p>This is your stuff, <i>Account</i> <ul><li><strong>TEST ONE</li></ul></p>

any ideas how i would use the update function into database.?

2
  • Maybe I missed something...why can't you modify it when you output it? Why do you NEED to have it stored with raw HTML? Apologies if I have missed something.....
    – GhostRider
    Jun 27, 2014 at 17:07
  • because i need http:// links also, i have not got the knowledge to modify it when it gets echo'd back out to html
    – Aide2001
    Jun 27, 2014 at 18:25

1 Answer 1

0

Depending on the way you are inputing the data, you could simply wrap up links in anchor tags and store them that way...

So for example if

 $link = "users link";

Simply

$input_string =  "<a href=\"$link\"" . $link . "</a>";

If only some of the users input is a link you could then use preg_match to first identify if the user input is a link. Then modify it as above before entering into the database.

Alternatively you could store the link simply as a string (i.e. in this case $link) in the database and when outputing add the anchor tags as above.

2
  • I haven't got a clue what or even how to use that code. If i type in <strong><h1>Hello</h1></strong> it goes into the database as that now as I put type="text" in the input field. But it now echo's the data from the database onto the website exactly as that and not in bold letters.
    – Aide2001
    Jun 27, 2014 at 19:16
  • If you are not using htmlentities or htmlspecialchars then your browser should be rendering the outputted html. My code above results in the link being entered into the database with anchor tags and a reference to the link, and when the data pulled from the database and echo'ed the html is rendered giving the link (in my case $link).
    – GhostRider
    Jun 27, 2014 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.