Hi, I have been trying to create a searchable database and have the following code for my form and the action code.

When the form is changed/submitted ll I get is an error "Query was empty"

Can anyone offer any help??

SEARCH By Last Name (Letter)<form NAME="navsel" action="sel_byLetter.php" method="get">

<select NAME="LETTER" ONCHANGE="document.forms[0].submit();">
<option>please select a Letter...
</option><option value="A">A
</option><option value="B">B
</option><option value="C">C
</option><option value="D">D
</option><option value="E">E
</option><option value="F">F
</option><option value="G">G
</option><option value="H">H
</option><option value="I">I
</option><option value="J">J
</option><option value="K">K
</option><option value="L">L
</option><option value="M">M
</option><option value="N">N
</option><option value="O">O
</option><option value="P">P
</option><option value="Q">Q
</option><option value="R">R
</option><option value="S">S
</option><option value="T">T
</option><option value="U">U
</option><option value="V">V
</option><option value="W">W
</option><option value="X">X
</option><option value="Y">Y
</option><option value="Z">Z
</option></select></form>

the action php code

$LETTER = $_GET;


if($LETTER[A]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='A' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[B]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='B' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[C]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='C' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[D]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='D' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[E]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='E' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[F]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='F' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[G]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='G' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[H]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='H' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[I]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='I' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[J]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='J' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[K]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='K' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[L]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='L' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[M]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='M' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[N]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='N' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[O]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='O' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[P]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='P' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[Q]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='Q' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[R]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='R' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[S]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='S' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[T]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='T' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[U]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='U' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[V]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='V' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[W]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='W' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[X]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='X' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[Y]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='Y' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}
elseif($LETTER[Z]){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='Z' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}


$result = @mysql_query($sql,$connection) or die(mysql_error());

All code files are php.
Any help is appreciated.

$LETTER = $_GET;

should be

$LETTER = $_GET['LETTER'];

P.S. using uppercase for variable names is not preferred by most programmers :)

wow, that is a lot of uneccessary code. why don't you use one sql query and just input the letter from the get array.

should be

$LETTER = $_GET['LETTER'];

P.S. using uppercase for variable names is not preferred by most programmers :)

Yeh I already did something similar to that. I changed the if () statement to

if($_GET[LETTER] == "A"){$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`,`LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`,`MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='A' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";}

This makes it work.

" wow, that is a lot of uneccessary code "
kkeith29,
Believe t or not the way I reworked this code removed alot of uneccessary code. I am always interested in clening it up more so, how would you reccomend cleaning it up.

how would you reccomend cleaning it up.

Like this ?

$letter = $_GET['LETTER'];
if(!empty($letter)) {
$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`, `LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`, `MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='".$letter."' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";
}

This one query will do exactly what you are trying to do with so many conditions and queries.

Like this ?

$letter = $_GET['LETTER'];
if(!empty($letter)) {
$sql = "SELECT `EndowmentNumber`,`LotSize`,`Letter`,`Section`, `LotNumber`,`LotOwner`,`LastName`,`FirstName`,`MiddleInitial`, `MaidenName`,`Suffix`,`Born`,`Died`,`VeteranInfo`,`MiscInfo` FROM `BurialsTable` WHERE Letter='".$letter."' ORDER BY `Letter`, `LastName`, `FirstName`, `FirstName`, `Section`, `LotNumber` ";
}

This one query will do exactly what you are trying to do with so many conditions and queries.

Thanks, It works Great. I tried to do this before but couldn't get it to work. That's why I stuck with the if/esleif statements. I see now one problem I had was I forgot the '.'(period) on each side of the $letter statement in the sql query.

Another question I have is: is it possible to have 2 auto submit (document.forms[0].submit();) forms on one page. If so how do I make it work?? I tried once, but the way I had it submitted both forms on the page. The first form, which was empty, took priority resulting in a error - (sql query empty).

Thanks again.

Hey, I seem to have an error in this page (attached file), but I can't seem to find it.
Maybe someone could look over it and find the problem.
I had been getting a unexpected $end error.
I got that resolved, but now I get a 'query was empty' error.
I double checked and I think I got it the same way as was listed above.
Of course any reccomendations are appreciated.
The config/db2.pp is simply the sql connect info.

The code fil is attached.

you are running mysql_query before you set $sql with the query.

commented: right.. +7

I knew whatever it was would be simple. Makes me feel dumb not catching that. Thanks a Lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.