Note: This is not related to the other topic "My First Snippet". I have not yet finished mine. I will lay everything out there in hopes that I can get some direction. This may end up being a stupid mistake or oversight on my part, which is typically the case. Here goes...
I inherited a small cemetery burial search website. The actual search itself seems pretty straightforward. You can try to find a gravesite by searching for six different parameters (First Name, Last Name, Date of Birth, Date of Death, Father’s Name, Mother’s Name). Since this site was inherited I installed a separate database on the same mysql server. So, I took the search.php and tried to create a snippet using this syntax to connect to the cemetery db:
$ds = $modx->db->select('*','Cemetery.burials');
The snippet shows up on a page with the search form, but when I attempt to search all I get is a white page with black text that reads "db select error" - not a modx parse error or anything, just that text. Here is my lame snippet:
<?php
include_once('lib/security.php');
$ds = $modx->db->select('*','Cemetery.burials');
error_reporting(0);
if(isset($_GET["reset"]))
{
unset($_SESSION["search"]);
}
if(isset($_POST["submit"]) || isset($_SESSION["burialsearchfirstname"]) || isset($_SESSION["burialsearchlastname"]))
{
if($_POST["cemetery"] == 0)
{
$cem = "";
}else
{
$cem = "cemeteryid=:cem";
}
if($_POST["fname"]!="" || $_SESSION["burialsearchfirstname"]!="")
{
if(isset($_SESSION["burialsearchfirstname"]))
{
$fname = "fname like :sfname";
}else
{
if($cem == "")
{
$fname = "fname like :fname";
}else
{
$fname = "and fname like :fname";
}
}
}else
{
$fname = "";
}
if($_POST["lname"]!="" || $_SESSION["burialsearchlastname"]!="")
{
if($_SESSION["burialsearchlastname"]!="")
{
if($_SESSION["burialsearchlastname"]!="" && $_SESSION["burialsearchfirstname"] !="")
{
$lname = "and lname like :slname";
}else
{
$lname = "lname like :slname";
}
}else
{
if($cem == "" && $fname == "")
{
$lname = "lname like :lname";
}else
{
$lname = "and lname like :lname";
}
}
}else
{
$lname = "";
}
if($_POST["death"] != "")
{
if($cem == "" && $fname == "" && $lname == "")
{
$death = "deathdate=:death";
}else
{
$death = "and deathdate=:death";
}
}else
{
$death = "";
}
if($_POST["birth"] != "")
{
if($cem == "" && $fname == "" && $lname == "" && $death == "")
{
$birth = "dateofbirth=:birth";
}else
{
$birth = "and dateofbirth=:birth";
}
}else
{
$birth = "";
}
if($_POST["fath"] != "")
{
if($cem == "" && $fname == "" && $lname == "" && $death == "" && $inter == "")
{
$fath = "father like :fath";
}else
{
$fath = "and father like :fath";
}
}else
{
$fath = "";
}
if($_POST["moth"] != "")
{
if($cem == "" && $fname == "" && $lname == "" && $death == "" && $inter == "" && $fath == "")
{
$moth = "mother like :moth";
}else
{
$moth = "and mother like :moth";
}
}else
{
$moth = "";
}
if($_POST["burialid"] != "")
{
if($cem == "" && $fname == "" && $lname == "" && $death == "" && $inter == "" && $fath == "" && $moth == "")
{
$burial = "burialid=:id";
}else
{
$burial = "and burialid=:id";
}
}else
{
$burial = "";
}
if($fname == "" && $lname == "" && $cem == "" && $birth == "" && $death == "" && $fath == "" && $moth == "" && $burial == "")
{
$where = "";
}else
{
$where = "WHERE";
}
$query = "SELECT * FROM burials $where $cem $fname $lname $death $birth $fath $moth $burial ORDER BY lname, fname limit 100";
$resultset = DoSQL($query, array("sfname" => $_SESSION["burialsearchfirstname"], "slname" => $_SESSION["burialsearchlastname"], "cem" => $_POST["cemetery"], "fname" => '%'.$_POST["fname"].'%', "lname" => '%'.$_POST["lname"].'%', "fath" => '%'.$_POST["fath"].'%', "moth" => '%'.$_POST["moth"].'%', "death" => $_POST["death"], "birth" => $_POST["birth"], "id" => $_POST["burialid"]), SQL_SELECT);
$_SESSION["searchdone"] = 1;
unset($_SESSION["burialsearchlastname"]);
unset($_SESSION["burialsearchfirstname"]);
/*$num = count($resultset);
$_SESSION["searcharray"] = array($resultset[0]["id"]);
for($x=1;$x<$num;$x++)
{
array_push($_SESSION["searcharray"], $resultset[$x]["id"]);
}*/
unset($_SESSION["searcharray"]);
unset($_SESSION["cursearchid"]);
$num = count($resultset);
$_SESSION["searcharray"] = array();
for($x=0;$x<$num;$x++) {
$_SESSION["searcharray"][] = $resultset[$x]["id"];
}
}
$title = "SpringvilleCemetery.org - Burial Search";
include_once('header.php');
if(!isset($_SESSION["searchdone"]))
{
?>
<table width="100%" cellspacing="10" cellpadding="0" align="center" border="0">
<tr>
<td valign="top" class="text">
<form name="searchform" action="" method="post">
<table>
<tr>
<td colspan="2" class="title">Search</td>
</tr>
<tr>
<td colspan="2"><p>
<label>
<input type="radio" name="cemetery" value="1" />
Springville City Cemetery</label>
<br />
<label>
<input type="radio" name="cemetery" value="2" />
Evergreen Cemetery</label>
<br />
<label>
<input type="radio" name="cemetery" value="0" checked />
I'm not sure</label>
</p></td>
</tr>
<tr>
<td class="title" colspan="2">For</td>
<br />
</tr>
<tr>
<td> Last Name <br />
<input type="text" name="lname" /></td>
<td>First Name <br />
<input type="text" name="fname" /> </td>
</tr>
<tr>
<td colspan="2" class="title"><br />
By</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td><br />
Date of Death (yyyy-mm-dd)<br />
<input type="text" name="death" />
</td>
<td><br />
Date of Birth (yyyy-mm-dd)<br />
<input type="text" name="birth" />
</td>
</tr>
<tr>
<td>
Fathers Name<br />
<input type="text" name="fath" />
</td>
<td>
Mothers Name<br />
<input type="text" name="moth" />
</td>
</tr>
<?php
if(isset($_SESSION["admin"]))
{
echo "<tr><td>Burial ID<br><input type=text name=burialid></td></tr>";
}
?>
<tr>
<td colspan="2"><br />
<input type="submit" name="submit" value="Search" />
</td>
</tr>
</table>
</form> </td>
</tr>
</table>
<?php
}else
{
?>
<table width="100%" cellspacing="10" cellpadding="0" align="center" border="0">
<tr>
<td valign="top" class="text"><p><span class="title">
Search Results</p>
<br>
<table width="100%">
<?
$numrows = count($resultset);
if($numrows == 0)
{
echo"<tr><td valign=top>Sorry there were no matches to your search criteria. Please expand your search.</td></tr>";
}else
{
for($r=0;$r<$numrows;$r++)
{
if($resultset[$r]['cemeteryid'] == "1")
{
$cem = "Springville Cemetery";
}elseif($resultset[$r]['cemeteryid'] == "2")
{
$cem = "Evergreen Cemetery";
}
echo "<tr>";
if(isset($_SESSION["admin"])){
echo "<td align=right>
<a href=view_burial.php?id=".$resultset[$r]['id'].">".$resultset[$r]['burialid']."</a>
</td>";
}
echo "<td valign=top>
<a href=view_burial.php?id=".$resultset[$r]['id'].">".$resultset[$r]['lname']."</a>
</td>";
echo "<td valign=top>";
echo $resultset[$r]['fname']."</td>";
echo "<td> </td>";
echo "<td valign=top>".$cem."</td>";
echo "</tr>";
}
}
echo "<tr><td><br><br><a href='search.php'>New Search</a><br><br></td></tr>";
?>
</table>
</td>
</tr>
</table>
<?php
unset($_SESSION["searchdone"]);
}
include_once('footer.php');
?>
<script language="javascript">
if (document.searchform){
document.searchform.lname.focus();
}
</script>
Any help or insight would be appreciated, thanks.