Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   MySQL vs PHP vs <textarea> (https://www.warriorforum.com/programming/436659-mysql-vs-php-vs-textarea.html)

Big Squid 20th August 2011 07:30 PM

MySQL vs PHP vs <textarea>
 
So I have a battle royal going on here...

I've got a php page, trying to insert into a MySQL db from an HTML textarea. Everything works grand, except when I have single quotes (') in the textarea.

I've checked the php.ini file and magic quotes are all OFF.
magic_quotes_gpc = Off
magic_quotes_runtime = Off
magic_quotes_sybase = Off

Anyone know what's going on, and how I can fix it?

Thanks for your help...

phpbbxpert 20th August 2011 09:52 PM

Re: MySQL vs PHP vs <textarea>
 
I can't think of any reason you would do this other than storing source code...

Your basically creating a time bomb if anyone from the public has a chance to access this form.
Your having issue with single quotes because you are injecting into the query.
You need to build some security into this and you wont have the issue.

addslashes($str);
mysql_real_escape($str);
htmlentities($str);

I would even go all out and do a str_replace() and preg_match() on some parts of the input and clean it further.
Then when it comes out, to display, do everything in reverse.

But like I said, Time Bomb, you really have to check and double check this input when allowing any type of user input into the database.
If there is a hole, some hacker will find it one day.

ereadergold 20th August 2011 10:30 PM

Re: MySQL vs PHP vs <textarea>
 
One thing you can do when storing raw HTML into a MySQL database is encode it to remove the "special " HTML characters, including the single-quote. When retrieving teh data you decode it to get back the original HTML string.

These two PHP functions will help you out:

PHP htmlspecialchars() Function

PHP htmlspecialchars_decode() Function


Hope this helps!

Bill

Big Squid 21st August 2011 03:00 AM

Re: MySQL vs PHP vs <textarea>
 
Thanks for the help. I'm actually only using it in development through xampp. But this does make want to go back through some other scripts and make them more secure...

I appreciate it..

bettor 29th August 2011 01:46 AM

Re: MySQL vs PHP vs <textarea>
 
if you are concerned with security you may try htmlPurifier and PDO (parameter binding when you write to DB)


All times are GMT -6. The time now is 09:30 PM.