PDA

View Full Version : php input field validation


jbroder
03-10-2000, 06:31 PM
I'm having trouble with a php input to mysql. Somebody put their info in "quotes" and the input didn't make it to the database.

So, I want to check all fields for " and change it to "

I could do this

eregi_replace('"','"' $field1)
eregi_replace('"','"' $field2)

But that gets tiring. Is there php variable for allfields?
Something like:

do {
eregi_replace('"','"' $field)
}
while ($allfields);

On a similar note:

is there a php way to say
if ($var isInTheList(1,2,3,4))

instead of
if (($var == 1) || ($var == 2) || ($var == 3) || ($var == 4))

Any help would be great. I checked the online manual and couldn't find these kinds of functions.

Jon

Shalazar
03-10-2000, 07:43 PM
If you're looking to change double quotes into their html equivalent, you need to use the function, htmlspecialchars().[nbsp][nbsp]Using htmlspecialchars($text) will convert any double quotes in the users input into " equivalent.

jbroder
03-10-2000, 08:50 PM
that's a lot easier.

Justin
03-10-2000, 10:31 PM
Two things - one, since you are not doing any pattern matching, it is best to use str_replace() - works the same, but doesn't use a regular expression (just replaces one string with another). Second, if you aren't using letters at all, no need to use eregi, which specifies case-insensitive matching... Though the htmlspecialchars() works for this purpose, always try to reduce it to the simplest possible method.

Just some friendly advice :)

------------------
Justin Nelson
FutureQuest (http://www.FutureQuest.net/index.php) Support

jbroder
03-13-2000, 04:51 PM
When I first started with futurequest I didnt even know how to change permissions on a file. Now I can code!

But I don't know the best way to do something, only the first way that worked.

So, any help about getting to the best/most efficient way is greatly appreciated.

Jon