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
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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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