Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 20th Aug 2011, 07:30 PM   #1
HyperActive Warrior
War Room Member
 
Big Squid's Avatar
 
Join Date: 2009
Location: Living between LA & SD
Posts: 205
Thanks: 27
Thanked 36 Times in 33 Posts
Default
MySQL vs PHP vs <textarea>
Share on: 
fb share twitter share gplus share more share

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...
Big Squid is offline  
Unread 20th Aug 2011, 09:52 PM   #2
Web Developer
 
Join Date: 2010
Location: Wisconsin
Posts: 322
Thanks: 2
Thanked 80 Times in 74 Posts
Default
Re: MySQL vs PHP vs <textarea>
Share on: 
fb share twitter share gplus share more share

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.

phpbbxpert is offline  
The Following User Says Thank You to phpbbxpert For This Useful Post:
Unread 20th Aug 2011, 10:30 PM   #3
VIP Warrior
War Room Member
 
ereadergold's Avatar
 
Join Date: 2008
Location: Montreal Canada
Posts: 2,390
Thanks: 1,017
Thanked 836 Times in 572 Posts
Blog Entries: 1
Default
Re: MySQL vs PHP vs <textarea>
Share on: 
fb share twitter share gplus share more share

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
ereadergold is offline  
The Following User Says Thank You to ereadergold For This Useful Post:
Unread 21st Aug 2011, 03:00 AM   #4
HyperActive Warrior
War Room Member
 
Big Squid's Avatar
 
Join Date: 2009
Location: Living between LA & SD
Posts: 205
Thanks: 27
Thanked 36 Times in 33 Posts
Default
Re: MySQL vs PHP vs <textarea>
Share on: 
fb share twitter share gplus share more share

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..
Big Squid is offline  
Unread 29th Aug 2011, 01:46 AM   #5
Warrior Member
 
Join Date: 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: MySQL vs PHP vs <textarea>
Share on: 
fb share twitter share gplus share more share

if you are concerned with security you may try htmlPurifier and PDO (parameter binding when you write to DB)
bettor is offline  
Closed Thread


Bookmarks

Tags
&lttextarea&gt, <textarea>, mysql, php


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 08:46 AM.