Re: Still need help with ereg

From: Date: Fri, 18 Apr 2003 07:13:03 +0000
Subject: Re: Still need help with ereg
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-144382@lists.php.net to get a copy of this message
I forgot to modify the string to be allowed into mySQL. Here we go again, (sorry). If you are trying to dump this into a database, namely mySQL, you are going to have to escape ' single-quotes, with single quotes. The slashes (which are a result of magic quotes) can be stripped if with strip slashes. All as demonstrated here: // remove excess slashes $formdata['lastname'] = stripslashes ($formdata['lastname']); // sets $error if lastname contains other than alpha or singlequote if (!ereg('^[a-zA-Z[:space:]\']*$', $formdata['lastname'])) {
    $error = 'Invalid Input';
} // escape singlequotes for mySQL $formdata['lastname'] = ereg_replace ("'", "''", $formdata['lastname']); Hope that helps. Note: I'd prefer to not mix and match, and to stay consistant using: if (!ereg('^[[:alpha:][:space:]\']*$', $formdata['lastname'])) { ... } -- der Ritter aka: Jason k Larson

« previous php.general (#144382) next »