Re: Still need help with ereg

From: Date: Fri, 18 Apr 2003 14:49:57 +0000
Subject: Re: Still need help with ereg
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-144409@lists.php.net to get a copy of this message
Nope, still confused. Let's go one step at a time. Whether I use \\' or \' the backslash is still allowed - that is the reason I tried two. The part about escaping the single-quotes with single quotes totally baffles me. I am putting this in a mysql database, but I'm not escaping anything with anything and the data appears to be the way it should. i.e. if the name O'Tool is entered in the form and then entered into the database, it shows up properly when I look at it in mysql - so I'm not sure what the purpose of this is. Thanks ----- Original Message ----- From: "Jason k Larson" <jlarson@candlefire.org> To: "C.R." <odcs@rogers.com> Cc: "PHP General" <php-general@lists.php.net> Sent: Friday, April 18, 2003 3:13 AM Subject: Re: [PHP] Still need help with ereg > 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 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#144409) next »