Re: Strange multple field query - problem

From: Date: Mon, 23 Oct 2000 02:32:01 +0000
Subject: Re: Strange multple field query - problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-21688@lists.php.net to get a copy of this message
On Sun, 22 Oct 2000, Helmut Ott wrote: > > 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? First, I would suggest you echo the value of $sql and see what you are (not) getting. I suspect that you might be mising some spaces in your query. If not, you may have problems where you are checking for empty variables; you might look at empty() and isset(). -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#21688) next »