Please can anyone help me? I have been pulling out what is left of my hair for two days on this!
I have built a cms for a website that allows the client to add new journal entries using php/mysql.
It worked absolutely fine in my test environment (PHP4.1.1) however, as soon as I put it into production (PHP5.1.2) it all went horribly wrong.
As you may have predicted from the post's title, the use of single or double quotes in entries is causing the insert/update queries to fail midway.
Now, if it was purely text I would use a function like:
to clean the string up pre query.
However, many of the exisitng entries (and also new ones) contain HTML tags for images, links etc.
The only workaround I can see is using the above function in the CMS prior to adding to/updating the DB and then using another function to "de-tag" on the pages where the data is to be displayed, such as:
This will require me to change a number of pages and seems like a lot of hard work
Is there an easier way around it?
The update code is shown below for info:
Thanks for reading.
I have built a cms for a website that allows the client to add new journal entries using php/mysql.
It worked absolutely fine in my test environment (PHP4.1.1) however, as soon as I put it into production (PHP5.1.2) it all went horribly wrong.
As you may have predicted from the post's title, the use of single or double quotes in entries is causing the insert/update queries to fail midway.
Now, if it was purely text I would use a function like:
Code:
$string = (htmlspecialchars(stripslashes($string), ENT_QUOTES));
to clean the string up pre query.
However, many of the exisitng entries (and also new ones) contain HTML tags for images, links etc.
The only workaround I can see is using the above function in the CMS prior to adding to/updating the DB and then using another function to "de-tag" on the pages where the data is to be displayed, such as:
Code:
$string = str_replace ( ''', '\'', $string ); etc
This will require me to change a number of pages and seems like a lot of hard work
Is there an easier way around it?
The update code is shown below for info:
Code:
mysql_connect("$host","$user","$password");
mysql_select_db("$database");
$n_o_t = $_POST['n_o_t'];
$post_date = $_POST['post_date'];
$post_content = $_POST['post_content'];
$post_title = $_POST['post_title'];
$sql="UPDATE journal SET post_date='$post_date',post_content='$post_content',post_title='$post_title' WHERE ID ='$id'";
//confirm done
$result = mysql_query($sql); }
Thanks for reading.