MySQL Forums
Forum List  »  Perl

Re: Please Help about update text
Posted by: Randy Clamons
Date: February 21, 2007 01:40PM

In the data that sometimes includes sql command and possibly other data, there may be ' characters. Since that is what you are using to delimit your text, you are going to need to escape the single quotes ('). Otherwise, mySql will not be able to parse your statement.

It's usually a good idea to escape all data--including numeric columns, especially if the form is to be used openly on the web. I use regular expressions to do the escaping:


sub mysql_escape {
	my $string = @_[0];
	$string =~ s/\\/\\\\/g ;
	$string =~ s/\n/\\n/g ;
	$string =~ s/\r//g ;
	$string =~ s/\'/\\\'/g;
	$string =~ s/\"/\\\"/g;
	return $string ;
}

There may be a better way to do this. This sub escapes the following characters:
Backslash(\), newline(\n), return (\r), single quote ('), double quote (").

To use in your code you could do something like:

$text5 = &mysql_escape($q->param('textarea'));

Options: ReplyQuote


Subject
Written By
Posted
February 15, 2007 04:40AM
Re: Please Help about update text
February 21, 2007 01:40PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.