Page 1 of 1

Processing empty fields from a form - PHP

Posted: Tue Oct 05, 2004 5:00 pm
by Calimero
Didn't know where exactly to put this, but here it goes:

If I have two fields in a form that I use to search DB, and user inputs something into the first, and nothing to the second (first case - he clicked in it and just passed by it, nothing was inputed; and in the second case he didn't even touched the field)

Is anything passed to php (with POST and/or GET methods) ?

I ask this because my mysql_query look's like this

SELECT *
FROM TABLE 1
WHERE col1 = "$input_field1" and col2 = "input_field2";

So my question is - will this (empty "value") field slow down my query, because (I think, but not sure - so I ask :) ) the value is empty - mysql will search trough the entire column.

And this gets more complicated (ouch my sleepy brain wants to get out of my creasy head) if I do EXPLODE in php before the query (of course I also TRIM it before querying).

Thanks in advance for the reply.

Posted: Tue Oct 05, 2004 5:08 pm
by feyd
empty form fields are sent to php and your script.

Posted: Tue Oct 05, 2004 5:12 pm
by Calimero
So in does php processes them as variables, or is there some built in mechanism to ignore empty strings ?!

Posted: Tue Oct 05, 2004 5:19 pm
by feyd
ignore how? they are just strings to php.. it barely cares what's inside them.. if you want the database to ignore them, then you need to ~dynamically build your query.

...

Posted: Tue Oct 05, 2004 5:48 pm
by Calimero
Ok thanks,

I presumed that something like that is the solution, but had to ask to be sure.

:wink:

Thank you !

Posted: Tue Oct 05, 2004 5:49 pm
by Calimero
Oh yeah, and I forgot the most important thing:

So in that case mysql is querying the entire column to find a match, right ?

Posted: Tue Oct 05, 2004 5:50 pm
by feyd
it does that anyways :P

...

Posted: Tue Oct 05, 2004 5:57 pm
by Calimero
Aha,
If you see a maniac that tried to delete all forms on the web - feel free to delete my account :D

Nyaaa, I'm gonna find some solution to make this super - functional :D :D

Enjoyed disscusing with you.

Thanks !