Posts: 3,343
Threads: 83
Joined: Mar 2003
If I have a form like:
Search the database
ID: 000
Name: xxxxxxxx
Last: xxxxxxx
Age: 00
And the person can fill in any or all of the fields and push "search", and a query goes off to the database, how do I make it work if they don't fill in all the fields?
Posts: 1,166
Threads: 62
Joined: Apr 2003
have a query building structure like
Code:
$query = "blah blah blah WHERE ";
if (isset($_POST['fname'])){
$query .= "name='". $_POST['fname']. "', ";
}
.......etc
I hope that helps a little...
am an asshole. Get used to it.
Posts: 3,343
Threads: 83
Joined: Mar 2003
It doesn't work!
I had to add single quotes in the third line down, right at the end between the ", "; double quotes, and I'm getting a parse error, I suspect because of the comma.
Now my queries look like SELECT blah FROM blah WHERE userid='', firstname='', lastname='', age=''
What should it look like?
Posts: 1,166
Threads: 62
Joined: Apr 2003
without the building... it'll be like this
Code:
WHERE name='something', stuff='something'
Sorry, I forgot a ' before the comma.
am an asshole. Get used to it.
Posts: 3,343
Threads: 83
Joined: Mar 2003
Hmmm... the if(isset( part doesn't seem to work, because I definately don't want blahblah='' do I. Any other way to check for a variable?
Posts: 1,166
Threads: 62
Joined: Apr 2003
isset checks to see if the variable has been set, even to nothing, so... you should check after the isset for something like
Code:
if (chop($_POST['fname']) != "")
To make sure it doesn't equal just empty space.
am an asshole. Get used to it.
Posts: 3,343
Threads: 83
Joined: Mar 2003
I'll check it later, when I'm in Linux (stupid bio project :wink: )
But if it works, thanks alot!