Jump to content


Photo

Insert/Update into MySQL database


  • Please log in to reply
3 replies to this topic

#1 snackiesmores

snackiesmores
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 22 March 2006 - 03:07 PM

Hello,

I think this question has a simple answer, yet it eludes me.. First time working with PHP, so I have a bit of a learning curve. I have a basic reporting tool that uses Apache/PHP with a MySQL back end DB. The forms are fairly simple, some text boxes and such. Submitting the form works just fine unless a field has a ' (tick mark) in it, such as:

[!--coloro:#CC0000--][span style=\"color:#CC0000\"][!--/coloro--].....The box contains a 'widget' of sorts......[!--colorc--][/span][!--/colorc--]

When a tick mark exists in the text of any field, NOTHING in the entire form gets pushed. I can only assume the problem is that when the submission query string is assembled, that the SQL processer thinks that the tick mark is actually part of the SQL statement, and not body text itself.

My question is, do i need to write a routine that searches for a ' and replaces it with \' ? or is there a PHP text pre-processer function (or something like that) that i can run chunk of text through that cleans it up? i.e., something that converts a " (quotation mark) to &quote; in XML.

#2 snackiesmores

snackiesmores
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 22 March 2006 - 07:57 PM

mmph.. no advice? only 2 looks other than myself :( i'm still actively searching for a solution but i dont think google likes my search phrases :P

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 22 March 2006 - 08:08 PM

When adding anything into a text (or varchar) field in MySQL you should always use either [a href=\"http://www.php.net/addslashes\" target=\"_blank\"]addslashes[/a]() or [a href=\"http://www.php.net/mysql_real_escape_string\" target=\"_blank\"]mysql_real_escape_string[/a]() on the values.

I prefer mysql_real_escape_string().

Ken

#4 snackiesmores

snackiesmores
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 22 March 2006 - 08:14 PM

ah thank you very much. I'll try that as soon as i get back to my dev machine :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users