lostinfmland
asked on
help creating a multi field php search form that gets data from mysql
I need some help fixing my form for some reason it does not work I can use a single text field for a search but, I cannot get more than one to work here is my code
form.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-
8859-1" />
<title>Passport To Languages Search Filemaker</title>
<link href="default.css" rel="stylesheet" type="text/css" media="screen" />
<script language="javascript" type="text/javascript">
window.onload=function(){
if(document.getElementById &&document .
getElementsByTagName&&docu ment.creat eElement){
var sfield=document.getElement sByTagName ('form')[0 ].elements [0];
if(!sfield){return};
sfield.onfocus=function(){ this.value =''};
sfield.onblur=function(){
if(!this.value){this.value ='Enter your search term here'};
}
}
}
</script>
</head>
<body>
<h1>Passport To Languages Search FileMaker</h1>
<div class="maincontainer">
<form method="get" action="processform.php">
<input type="text" name="searchterm" title="Enter your search
term here" value="Enter your search term here"
class="searchbox" />
Patient Last Name:<input type="text" name="searchterm1" title="Patient Last Name" value="Enter your search term here"
class="searchbox" /><br>
Recipient ID:<input type="text" name="searchterm2" title="Recipient ID" value="Enter your search term here"
class="searchbox" /><br>
Phone Number:<input type="text" name="searchterm3" title="Phone Number" value="Enter your search term here"
class="searchbox" /><br>
Date of Service:<input type="text" name="searchterm4" title="Date of Service" value="Start Date"
class="searchbox" /><br>
</form>
</div>
</body>
</html>
processform.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
// include MySQL-processing classes
require_once 'mysql.php';
try{
// connect to MySQL
$db=new MySQL(array ('host'=>'','user'=>'','pa ssword'=>' ',
'database'=>'mydb'));
$searchterm=$db->escapeStr ing($_GET[ 'searchter m']);
$searchterm1=$db->escapeSt ring($_GET ['searchte rm1']);
$searchterm2=$db->escapeSt ring($_GET ['searchte rm2']);
$searchterm3=$db->escapeSt ring($_GET ['searchte rm3']);
$searchterm4=$db->escapeSt ring($_GET ['searchte rm4']);
$searchterm4 = date('Y/m/d', strtotime($searchterm4));
$result=$db->query("SELECT * FROM data WHERE (at_client_sn)='423' AND (at_claimant_first_name)=' %$searchte rm%' AND (at_claimant_last_name)='% $searchter m1%' AND (at_case)='%$searchterm2%' AND (at_claimant_phone_number) ='%$search term3%' AND (at_date) =$searchterm4");
if(!$result->countRows()){
echo '<div class="maincontainer"><h2> No results were found. Go
back and try a new search.</h2></div>'."n";
}
else{
// display search results
echo '<div class="maincontainer"><h2> Your search criteria
returned '.$result->countRows().' results.</h2>'."";
echo "<table border='1'><center>";
echo "<tr><th>Appointment#</th> <th>Date</th> <th>Time........</th> <th>Language</th> <th>Patient Name</th> <th>Interpreters First Name</th> <th>INTERPRETERS Last..Name</th> </tr>";
while($row=$result->fetchR ow()){
echo "<tr onclick=thisfunction();> <td>";
echo "<tr>";
echo "<td>" . $row['appointment_sn_text' ] . "</td>";
echo "<td>" . $row['at_date'] . "</td>";
echo "<td>" . $row['at_time'] . "</td>";
echo "<td>" . $row['at_language'] . "</td>";
echo "<td>" . $row['at_claimant_first_na me'] . "</td>";
echo "<td>" . $row['INTERPRETERSbyInterp reterSN::i r_first_na me'] . "</td>";
echo "<td>" . $row ['INTERPRETERSbyInterprete rSN::ir_la st_name'] . "</td>";
echo "<td>" . "<a href='display.php?id=".$ro w['appoint ment_sn_te xt']."'>Di splay</a>" . "</td>";
echo "</tr>";
}
}
echo "</table>";
}
catch(Exception $e){
echo $e->getMessage();
exit();
}
?>
and mysql.php
<?php
// define 'MySQL' class
class MySQL{
private $conId;
private $host;
private $user;
private $password;
private $database;
private $result;
const OPTIONS=4;
public function __construct($options=array ()){
if(count($options)!=self:: OPTIONS){
throw new Exception('Invalid number of connection parameters');
}
foreach($options as $parameter=>$value){
if(!$value){
throw new Exception('Invalid parameter '.$parameter);
}
$this->{$parameter}=$value ;
}
$this->connectDB();
}
// connect to MySQL
private function connectDB(){
if(!$this->conId=mysql_con nect($this ->host,$th is->user,$ this->pass word)){
throw new Exception('Error connecting to the server');
}
if(!mysql_select_db($this- >database, $this->con Id)){
throw new Exception('Error selecting database');
}
}
// run query
public function query($query){
if(!$this->result=mysql_qu ery($query ,$this->co nId)){
throw new Exception('Error performing query '.$query);
}
return new Result($this,$this->result );
}
public function escapeString($value){
return mysql_escape_string($value );
}
}
// define 'Result' class
class Result {
private $mysql;
private $result;
public function __construct(&$mysql,$resul t){
$this->mysql=&$mysql;
$this->result=$result;
}
// fetch row
public function fetchRow(){
return mysql_fetch_assoc($this->r esult);
}
// count rows
public function countRows(){
if(!$rows=mysql_num_rows($ this->resu lt)){
return false;
}
return $rows;
}
// count affected rows
public function countAffectedRows(){
if(!$rows=mysql_affected_r ows($this- >mysql->co nId)){
throw new Exception('Error counting affected rows');
}
return $rows;
}
// get ID form last-inserted row
public function getInsertID(){
if(!$id=mysql_insert_id($t his->mysql ->conId)){
throw new Exception('Error getting ID');
}
return $id;
}
// seek row
public function seekRow($row=0){
if(!is_int($row)||$row<0){
throw new Exception('Invalid result set offset');
}
if(!mysql_data_seek($this- >result,$r ow)){
throw new Exception('Error seeking data');
}
}
}
?>
form.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-
8859-1" />
<title>Passport To Languages Search Filemaker</title>
<link href="default.css" rel="stylesheet" type="text/css" media="screen" />
<script language="javascript" type="text/javascript">
window.onload=function(){
if(document.getElementById
getElementsByTagName&&docu
var sfield=document.getElement
if(!sfield){return};
sfield.onfocus=function(){
sfield.onblur=function(){
if(!this.value){this.value
}
}
}
</script>
</head>
<body>
<h1>Passport To Languages Search FileMaker</h1>
<div class="maincontainer">
<form method="get" action="processform.php">
<input type="text" name="searchterm" title="Enter your search
term here" value="Enter your search term here"
class="searchbox" />
Patient Last Name:<input type="text" name="searchterm1" title="Patient Last Name" value="Enter your search term here"
class="searchbox" /><br>
Recipient ID:<input type="text" name="searchterm2" title="Recipient ID" value="Enter your search term here"
class="searchbox" /><br>
Phone Number:<input type="text" name="searchterm3" title="Phone Number" value="Enter your search term here"
class="searchbox" /><br>
Date of Service:<input type="text" name="searchterm4" title="Date of Service" value="Start Date"
class="searchbox" /><br>
</form>
</div>
</body>
</html>
processform.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
// include MySQL-processing classes
require_once 'mysql.php';
try{
// connect to MySQL
$db=new MySQL(array ('host'=>'','user'=>'','pa
'database'=>'mydb'));
$searchterm=$db->escapeStr
$searchterm1=$db->escapeSt
$searchterm2=$db->escapeSt
$searchterm3=$db->escapeSt
$searchterm4=$db->escapeSt
$searchterm4 = date('Y/m/d', strtotime($searchterm4));
$result=$db->query("SELECT
if(!$result->countRows()){
echo '<div class="maincontainer"><h2>
back and try a new search.</h2></div>'."n";
}
else{
// display search results
echo '<div class="maincontainer"><h2>
returned '.$result->countRows().' results.</h2>'."";
echo "<table border='1'><center>";
echo "<tr><th>Appointment#</th>
while($row=$result->fetchR
echo "<tr onclick=thisfunction();> <td>";
echo "<tr>";
echo "<td>" . $row['appointment_sn_text'
echo "<td>" . $row['at_date'] . "</td>";
echo "<td>" . $row['at_time'] . "</td>";
echo "<td>" . $row['at_language'] . "</td>";
echo "<td>" . $row['at_claimant_first_na
echo "<td>" . $row['INTERPRETERSbyInterp
echo "<td>" . $row ['INTERPRETERSbyInterprete
echo "<td>" . "<a href='display.php?id=".$ro
echo "</tr>";
}
}
echo "</table>";
}
catch(Exception $e){
echo $e->getMessage();
exit();
}
?>
and mysql.php
<?php
// define 'MySQL' class
class MySQL{
private $conId;
private $host;
private $user;
private $password;
private $database;
private $result;
const OPTIONS=4;
public function __construct($options=array
if(count($options)!=self::
throw new Exception('Invalid number of connection parameters');
}
foreach($options as $parameter=>$value){
if(!$value){
throw new Exception('Invalid parameter '.$parameter);
}
$this->{$parameter}=$value
}
$this->connectDB();
}
// connect to MySQL
private function connectDB(){
if(!$this->conId=mysql_con
throw new Exception('Error connecting to the server');
}
if(!mysql_select_db($this-
throw new Exception('Error selecting database');
}
}
// run query
public function query($query){
if(!$this->result=mysql_qu
throw new Exception('Error performing query '.$query);
}
return new Result($this,$this->result
}
public function escapeString($value){
return mysql_escape_string($value
}
}
// define 'Result' class
class Result {
private $mysql;
private $result;
public function __construct(&$mysql,$resul
$this->mysql=&$mysql;
$this->result=$result;
}
// fetch row
public function fetchRow(){
return mysql_fetch_assoc($this->r
}
// count rows
public function countRows(){
if(!$rows=mysql_num_rows($
return false;
}
return $rows;
}
// count affected rows
public function countAffectedRows(){
if(!$rows=mysql_affected_r
throw new Exception('Error counting affected rows');
}
return $rows;
}
// get ID form last-inserted row
public function getInsertID(){
if(!$id=mysql_insert_id($t
throw new Exception('Error getting ID');
}
return $id;
}
// seek row
public function seekRow($row=0){
if(!is_int($row)||$row<0){
throw new Exception('Invalid result set offset');
}
if(!mysql_data_seek($this-
throw new Exception('Error seeking data');
}
}
}
?>
ASKER
I tried that code and it does not work. It works if you limit just by a single field.
ASKER
I mean if you remove all the other fields and just leave one their IE.
$result=$db->query("SELECT * FROM data WHERE at_claimant_first_name LIKE ' %$searchterm%''");
$result=$db->query("SELECT
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
please see code below..
Open in new window
br,
Open in new window