Jump to content

MySQL storing quotes


M4verick

Recommended Posts

Hello all. I've had a question regarding some data I'm trying to store in MySQL.

 

I'm creating a basic trouble ticketing system for some php/mysql practice. When someone posts some data, if it has ' or " in it, it goes through fine. However, I tried to make it that when it is updated, it appends the new stuff to the end of the old stuff. However, it loses the chunk of data where the ' or " is at.

 

I had been using mysql_real_escape_string() to store the data. But when I call it for viewing, I see more characters added (r\n\. The magic_quotes_gpc is disabled in the php.ini

 

Despite the extra characters, when I append the new info to the variable with the old information, if there are any more ' or " and commas, then it cuts of a chunk of the old data, and the new information is stored just fine. Repeat as information is added.

 

So, what am I doing wrong here?

 

This is how I'm storing it originally. I just throw $prob in the database.

$prob = mysql_real_escape_string($_POST['prob']);

 

Everytime after that is done like this -

$poster = $_SESSION['username'];
$lasttouched = $poster."/".date("D M j G:i:s T Y");
$oldbody = mysql_real_escape_string($_POST['body']);
$newbody = mysql_real_escape_string($_POST['bodyupdate']);
$updatebody = $oldbody."<p />".$lasttouched." - ".$newbody;
$body = mysql_real_escape_string($updatebody);

Which I then send $body to the database.

 

I did try adding stripslashes() to the data it restores, then it appends the new data, and redoes the mysql_real_escape_string()

 

Is this wrong? I'm finding a lot of conflicting information.

Link to comment
https://forums.phpfreaks.com/topic/197335-mysql-storing-quotes/
Share on other sites

Scratch that, I was able to get it to work, I had more issues that I had to resolve. Thank you kindly. So for clarification if any posters in the future regard this thread...

 

Run this for sending it do the database -

htmlentities($string, ENT_QUOTES);

 

And this for retrieving -

html_entity_decode($string);

Archived

This topic is now archived and is closed to further replies.

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