[SOLVED] Processing empty fields from a form - PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Processing empty fields from a form - PHP

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

empty form fields are sent to php and your script.
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Post by Calimero »

So in does php processes them as variables, or is there some built in mechanism to ignore empty strings ?!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post by Calimero »

Ok thanks,

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

:wink:

Thank you !
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Post 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 ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it does that anyways :P
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post 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 !
Post Reply