Forum Moderators: coopster

Message Too Old, No Replies

mysql real escape string() or CharSet Error

         

camilord

5:46 am on Jun 9, 2007 (gmt 0)

10+ Year Member



i having trouble with this...

I used tinyMCE as my rich text editor... and in my paragraph, it contain like this...

[html code snipset]

<a href="../%22../%22http://www.example.com/x.pdf/%22/%22" target="/&quot;_blank/&quot;">

[/html code snipset]

now when it will be inserted in the database, i used this....

[php code snipset]

$article = $_POST["article"];

$sql = "insert into news (article) values ('%s')";
$result = mysql_query(sprintf($sql,mysql_real_escape_string($article)));

if ($result)
{
return 'ok';
}
else
{
return 'err';
}

[/php code snipset]

now, when i retrieve the data from the mysql, i gives me like this... shown below...

[html code snipset]
<a href="../%22../%22http://www.example.com/x.pdf/%22/%22" target="/&quot;_blank/&quot;">
[/html code snipset]

is there something wrong in my php code? coz in my computer, running windows, php 4.3.11 and mysql 5.0.1-alpha, it works fine. but in my server, running CPanel, that's the output.. please help...

[edited by: eelixduppy at 6:23 am (utc) on June 9, 2007]
[edit reason] example.com [/edit]

camilord

5:49 am on Jun 9, 2007 (gmt 0)

10+ Year Member



[REVISE] hehehee..
==============================
i having trouble with this...

I used tinyMCE as my rich text editor... and in my paragraph, it contain like this...

[html code snipset]

<a href="../%22../%22http://www.example.com/x.pdf/%22/%22" target="/&quot;_blank/&quot;">

[/html code snipset]

now when it will be inserted in the database, i used this....

[php code snipset]

$article = $_POST["article"];

$sql = "insert into news (article) values ('%s')";
$result = mysql_query(sprintf($sql,mysql_real_escape_string($article)));

if ($result)
{
return 'ok';
}
else
{
return 'err';
}

[/php code snipset]

now, when i retrieve the data from the mysql, i gives me like this... shown below...

[html code snipset]
<a href="://www.example.com/x.pdf" target="_blank">
[/html code snipset]

is there something wrong in my php code? coz in my computer, running windows, php 4.3.11 and mysql 5.0.1-alpha, it works fine. but in my server, running CPanel, that's the output.. please help...

[edited by: eelixduppy at 6:23 am (utc) on June 9, 2007]
[edit reason] example.com [/edit]

camilord

5:49 am on Jun 9, 2007 (gmt 0)

10+ Year Member



[FINAL REVISE] ========================
==============================

i having trouble with this...

I used tinyMCE as my rich text editor... and in my paragraph, it contain like this...

[html code snipset]

<a href="http://www.example.com/x.pdf" target="_blank">

[/html code snipset]

now when it will be inserted in the database, i used this....

[php code snipset]

$article = $_POST["article"];

$sql = "insert into news (article) values ('%s')";
$result = mysql_query(sprintf($sql,mysql_real_escape_string($article)));

if ($result)
{
return 'ok';
}
else
{
return 'err';
}

[/php code snipset]

now, when i retrieve the data from the mysql, i gives me like this... shown below...

[html code snipset]
<a href="../%22../%22http://www.example.com/x.pdf/%22/%22" target="/&quot;_blank/&quot;">
[/html code snipset]

is there something wrong in my php code? coz in my computer, running windows, php 4.3.11 and mysql 5.0.1-alpha, it works fine. but in my server, running CPanel, that's the output.. please help...

[edited by: eelixduppy at 6:24 am (utc) on June 9, 2007]
[edit reason] example.com [/edit]

coopster

2:56 am on Jun 13, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm guessing by the level of responses I'm not the only one that is confused here ...

Can you view the values in the database table directly without running them through a script? If so, is the data going into the database table as you desire? If not, then I would dump the variable to the screen right after the POST but before the INSERT to see what the variable contains and then work my way back from there.