Francesco
Francesco

Reputation: 25269

mysql+php: how to store a html string AS IS

i need to store s tring like this, AS IS in mysql

member of the ruling <a href="/tets/Polish_United_Workers%27_Party" 

but in mysql the %27 is concerted to ' char

how can i keep the sql respecting exactly the string as is?

UPDATE:

I send the text

var string = 'member of the ruling <a href="/tets/Polish_United_Workers%27_Party"'

from javascript to php (maybe the problem is here?)

$.ajax({
url: myurl,
async:false,
data: "text="+string,
type: "POST",
success: function( data ) {....etc...

parte of the sql query on the php file receiving the js call

text = addslashes($_POST["text"])

Upvotes: 0

Views: 623

Answers (2)

mpen
mpen

Reputation: 283355

use

data: {text:string}

instead and let jquery handle the encoding for you. when you insert it to your DB you can call mysql_real_escape_string on it before inserting it so that you're not vulnerable to SQL injection and everything gets escaped properly, or use a more modern database abstraction layer (PDO).

Upvotes: 1

Francesco
Francesco

Reputation: 25269

my bad, i overlooked it and YEs the solution was to add escape(string) before submitting to php

arrrhggg

Upvotes: 0

Related Questions