Link to home
Start Free TrialLog in
Avatar of lostinfmland
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&&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');

}

}

}

?>

 



Avatar of Frozenice
Frozenice
Flag of Philippines image

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

Avatar of lostinfmland
lostinfmland

ASKER

I tried that code and it does not work. It works if you limit just by a single field.
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%''");
ASKER CERTIFIED SOLUTION
Avatar of PranjalShah
PranjalShah
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial