Strange multple field query - problem

From: Date: Sun, 22 Oct 2000 00:25:53 +0000
Subject: Strange multple field query - problem
Groups: php.general 
Request: Send a blank email to php-general+get-21609@lists.php.net to get a copy of this message
Shoudnt be so tricky, but I actually spent a lot of hours without getting the multiple-field-query running: Thats what I am doing, I am trying to be exact: I have a form with 3 fields to select records from a database "db": Filename is search.php <form action=$PHP_SELF method=get> <input type=text name=type value=""> (entered value e.g. aaa) <input type=text name=name value=""> (entered value e.g. bbb) <input type=text name=year value=""> (entered value e.g. ccc) <input type=submit value="search "> <input type=hidden name=func value="search"> </form> Submitting the form produces the following url-string in the browser: /path/to/file/search.php?field1=aaa&field2=bbb&field3=ccc The file calls itself again and continues parsing in the script where it finds : $func=search Before concatenating the sql-querystring each variable has to be checked if empty. If empty it is omitted from the query. $sql="SELECT * FROM table WHERE"; if($type !="") {$sql.="type='$type' AND"} if($name !="") {$sql.="name='$name' AND"} if($year !="") {$sql.="year='$year'"} the $sql/sql_string is: "SELECT * FROM table WHERE type='$type' AND name='$name' AND '$year'"; THE PROBLEM: When running the following query, the "$sql"-part is not parsed and the query does not bring results. $result=mysqlquery(db, $sql) What the hell is wrong here? Does anybody have a working example? Thanks alot Helmut

« previous php.general (#21609) next »