Re: Still need help with ereg

From: Date: Fri, 18 Apr 2003 15:01:14 +0000
Subject: Re: Still need help with ereg
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-144410@lists.php.net to get a copy of this message
Maybe your PHP environment has magic_quotes turned on. This means that things like O'Tool are automatically dealt with so you don't have to do \' Ben At 10:49 18/04/2003 -0400, C.R. wrote: >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 > > > > > > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php > > > >--- >Incoming mail is certified Virus Free. >Checked by AVG anti-virus system (http://www.grisoft.com). >Version: 6.0.471 / Virus Database: 269 - Release Date: 10/04/2003 **************************************************************** * Ben Edwards Tel +44 (0)117 968 2602 ICQ 42000477 * * Critical Site Builder http://www.criticaldistribution.com * * online collaborative web authoring content management system * * Get alt news/views films online http://www.cultureshop.org * * i-Contact Progressive Video http://www.videonetwork.org * * Fun corporate graphics http://www.subvertise.org * * Bristol Indymedia http://bristol.indymedia.org * * Bristol's radical news http://www.bristle.org.uk * ****************************************************************

« previous php.general (#144410) next »