here are my codes
searchByCategor yForm.php
init.js
search.js
searchByCategor y.php
my database is
i dont know whats the problem but base on my observation the code didn't go to database..Pleas e help
any suggestions are very appreciated..th anks
searchByCategor yForm.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title></title> <link rel="stylesheet" type="text/css" href="style2.css" /> <script type="text/javascript" src="init.js"></script> <script type="text/javascript" src="search.js"></script> </head> <body onload='initRequest()'> <div> Search By:<select name="category" id="category" onChange="searchCategory()"> <option value="name">Name</option> <option value="serviceID">ServiceID</option> </select> <input name="search" type="text" id='search' size="40" onKeyup="searchCategory()"> <div id="searchResult"></div> </div> </body> </html>
Code:
var http;
function initRequest()
{
if (window.XMLHttpRequest)
{
http = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
http = new ActiveXObject("Microsoft.XMLHTTP");
}
}
Code:
function searchCategory()
{
var category=document.getElementById("category").value;
if (category=='serviceID')
{
if(document.getElementById("search").value.length==2)
{
var format=(document.getElementById("search").value)+"-LP-"
document.getElementById("search").value=format;
}
}
var snput=document.getElementById("search").value;
var params="category="+category+"&nput="+snput;
var url="searchByCategory.php";
searchCat(url,params);
}
function searchCat(url,params)
{
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function()
{//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200)
{
x=http.responseText;
document.getElementById("searchResult").innerHTML=x;
}
}
http.send(params);
}
Code:
<?php
include 'config/opendb.php';
$category = $_POST['category'];
$nput=$_POST['nput'];
if($category == 'name')
{
$searchQuery = "SELECT ServiceID, ClientLastName, ClientFirstName
FROM service a, client b
WHERE a.ClientID = b.ClientID
AND CONCAT(ClientLastName,',', ClientFirstName) LIKE '$nput%'";
}
elseif($category == 'serviceID')
{
$searchQuery = "SELECT ServiceID, ClientLastName, ClientFirstName
FROM service a, client b
WHERE a.ClientID = b.ClientID
AND ServiceID LIKE '$nput%'";
}
$res = mysql_query($searchQuery) or die("Error:searchCategory.php--->".mysql_error());
$ctr=0;
echo "<table cellspacing='1' style='width:100%;>
<tr><font color='black'>
<td bgcolor='#E7ECFD' width='100' align='center'><strong>ServiceID</strong></td>
<td bgcolor='#E7ECFD' width='400' align='center'><strong>LastName</strong></td>
<td bgcolor='#E7ECFD' width='400' align='center'><strong>FirstName</strong></td>
<td bgcolor='#E7ECFD' width='200' align='center'><strong>Service Proposal</strong></td>
</font></tr>";
while(list($serviceID, $clientLastName, $clientFirstName)=mysql_fetch_array($res))
{
if($ctr%2==0)
{
echo "<form action='serviceProposal.php' method=POST><tr><font color='black'>
<td bgcolor='#CCCCCC' width='100' align='center'>$serviceID<input type=hidden name=\"serviceID\" value=\"$serviceID\"></td>
<td bgcolor='#CCCCCC' width='400' align='center'>$clientLastName<input type=hidden name=\"clientLastName\" value=\"$clientLastName\"></td>
<td bgcolor='#CCCCCC' width='400' align='center'>$clientFirstName<input type=hidden name=\"clientFirstName\" value=\"$clientFirstName\"></td>
<td bgcolor='#CCCCCC' width='200' align='center'><input type=submit name='serviceProposal' value='Create Service Proposal''></td>
</font></tr></form>";
}
else
{
echo "<form action='bookingOrder.php' method=POST><tr><font color='black'>
<td bgcolor='#CEE7FF' width='100' align='center'>$serviceID<input type=hidden name=\"serviceID\" value=\"$serviceID\"></td>
<td bgcolor='#CEE7FF' width='400' align='center'>$clientLastName<input type=hidden name=\"clientLastName\" value=\"$clientLastName\"></td>
<td bgcolor='#CEE7FF' width='400' align='center'>$clientFirstName<input type=hidden name=\"clientFirstName\" value=\"$clientFirstName\"></td>
<td bgcolor='#CEE7FF' width='200' align='center'><input type=submit name='serviceProposal' value='Create Service Proposal' onClick='showserviceproposalform()'></td>
</font></tr></form>";
}
$ctr++;
}
print "</table>";
include 'config/closedb.php';
?>
Code:
CREATE TABLE `client` ( `ClientID` int(11) NOT NULL AUTO_INCREMENT, `ClientFirstName` varchar(50) NOT NULL, `ClientLastName` varchar(50) NOT NULL, PRIMARY KEY (`ClientID`) ) CREATE TABLE `service` ( `ServiceID` varchar(14) NOT NULL, `ClientID` int(11) DEFAULT NULL, )
any suggestions are very appreciated..th anks
Comment