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&&document.createElement){

var sfield=document.getElementsByTagName('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'=>'','password'=>'',
'database'=>'mydb'));

$searchterm=$db->escapeString($_GET['searchterm']);
 $searchterm1=$db->escapeString($_GET['searchterm1']);
$searchterm2=$db->escapeString($_GET['searchterm2']);
$searchterm3=$db->escapeString($_GET['searchterm3']);
$searchterm4=$db->escapeString($_GET['searchterm4']);
$searchterm4 = date('Y/m/d', strtotime($searchterm4));


$result=$db->query("SELECT * FROM data WHERE (at_client_sn)='423' AND (at_claimant_first_name)='%$searchterm%' AND (at_claimant_last_name)='%$searchterm1%' AND (at_case)='%$searchterm2%' AND (at_claimant_phone_number)='%$searchterm3%' 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->fetchRow()){

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_name'] . "</td>";
echo "<td>" . $row['INTERPRETERSbyInterpreterSN::ir_first_name'] . "</td>";
echo "<td>" . $row ['INTERPRETERSbyInterpreterSN::ir_last_name'] . "</td>";
echo "<td>" . "<a href='display.php?id=".$row['appointment_sn_text']."'>Display</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_connect($this->host,$this->user,$this->password)){

throw new Exception('Error connecting to the server');

}

if(!mysql_select_db($this->database,$this->conId)){

throw new Exception('Error selecting database');

}

}

// run query

public function query($query){

if(!$this->result=mysql_query($query,$this->conId)){

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,$result){

$this->mysql=&$mysql;

$this->result=$result;

}

// fetch row

public function fetchRow(){

return mysql_fetch_assoc($this->result);

}

// count rows

public function countRows(){

if(!$rows=mysql_num_rows($this->result)){

return false;

}

return $rows;

}

// count affected rows

public function countAffectedRows(){

if(!$rows=mysql_affected_rows($this->mysql->conId)){

throw new Exception('Error counting affected rows');

}

return $rows;

}

// get ID form last-inserted row

public function getInsertID(){

if(!$id=mysql_insert_id($this->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,$row)){

throw new Exception('Error seeking data');

}

}

}

?>

 



lostinfmlandAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FrozeniceCommented:
hi...


please see code below..


$result=$db->query("SELECT * FROM data WHERE at_client_sn='423' AND at_claimant_first_name LIKE '%$searchterm%' AND at_claimant_last_name LIKE '%$searchterm1%' AND at_case LIKE '%$searchterm2%' AND at_claimant_phone_number LIKE '%$searchterm3%' AND at_date ='$searchterm4'");

Open in new window



br,
$result=$db->query("SELECT * FROM data WHERE at_client_sn='423' AND at_claimant_first_name LIKE '%$searchterm%' AND at_claimant_last_name LIKE '%$searchterm1%' AND at_case LIKE '%$searchterm2%' AND at_claimant_phone_number LIKE '%$searchterm3%' AND at_date ='$searchterm4'");

Open in new window

0
lostinfmlandAuthor Commented:
I tried that code and it does not work. It works if you limit just by a single field.
0
lostinfmlandAuthor Commented:
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%''");
0
PranjalShahCommented:
I think your column at_client_sn is unique or not repeated again..so try removing the condition at_client_sn and see wat happens

One more thing I noticed is you are using "AND" operator to get the results in the query...I am not sure if that is what you want to do. Since you want to expand your search as much as possible to get the results. And using AND operator you are limiting it. Try using OR ...


$result=$db->query("SELECT * FROM data WHERE at_claimant_first_name LIKE '%$searchterm%' OR at_claimant_last_name LIKE '%$searchterm1%' OR at_case LIKE '%$searchterm2%' OR at_claimant_phone_number LIKE '%$searchterm3%' OR at_date ='$searchterm4'");
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.