Page 1 of 1

Private Messaging

Posted: Fri Sep 20, 2013 12:37 pm
by Epiales
Hey all... I've setup a private messaging system now. It works great, but it won't let me send any apostrophe's in the text. If I just enter the word:

Code: Select all

I've
I get this error:

Code: Select all

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 've','Re: Looping Battles','4486329')' at line 2
How can I fix that?

Re: Private Messaging

Posted: Fri Sep 20, 2013 12:46 pm
by vitinho444
Let's say you are POSTING the form to other page or even the same as the name: $_POST["message"]

Whenever you put that in your db just remember to escape first

Code: Select all

//XSS Security
	function Escape($t)
	{
		return htmlentities($t, ENT_QUOTES);
	}
That prevents XSS (tutorial i used is in IR), and allows you to have single and double quotes without damaging the query ;)

PS: You don't need the function i have, just use: htmlentities($_POST["message"], ENT_QUOTES);

Re: Private Messaging

Posted: Fri Sep 20, 2013 12:47 pm
by OldRod
Sounds like you are not escaping the string properly.

It's been a while, but I think mysql_real_escape_string fixes this:

http://php.net/manual/en/function.mysql ... string.php

Re: Private Messaging

Posted: Fri Sep 20, 2013 12:51 pm
by Epiales
vitinho444 wrote:Let's say you are POSTING the form to other page or even the same as the name: $_POST["message"]

Whenever you put that in your db just remember to escape first

Code: Select all

//XSS Security
	function Escape($t)
	{
		return htmlentities($t, ENT_QUOTES);
	}
That prevents XSS (tutorial i used is in IR), and allows you to have single and double quotes without damaging the query ;)

PS: You don't need the function i have, just use: htmlentities($_POST["message"], ENT_QUOTES);
Worked perfect! Thank you!

Re: Private Messaging

Posted: Fri Sep 20, 2013 12:51 pm
by Epiales
OldRod wrote:Sounds like you are not escaping the string properly.

It's been a while, but I think mysql_real_escape_string fixes this:

http://php.net/manual/en/function.mysql ... string.php
Thanks, I'll read on that as well ;)

Re: Private Messaging

Posted: Fri Sep 20, 2013 1:28 pm
by vitinho444
Worked perfect! Thank you!
This is some inspiration for people to help... Wow i'm addicted to helping people.

Re: Private Messaging

Posted: Fri Sep 20, 2013 1:33 pm
by Epiales
vitinho444 wrote:
Worked perfect! Thank you!
This is some inspiration for people to help... Wow i'm addicted to helping people.
Yes... When someone asks something that I know? I'll be the first to help :lol: :lol:

And you both were fast at answering. YAY to you both. :mrgreen: :mrgreen: :mrgreen: