Page 1 of 1

search form using php HELP

Posted: Wed Aug 11, 2010 4:03 pm
by newtoprograming1221
FORM
<table border=0 cellpadding=2 cellspacing=0 width=900 align=center>
<tr align=right bgcolor=#ECE5B6>
<td>
<form target="_self" action="search.php" method="post"><b>
Search by:
<select name="drpdb">
<option value="RequesterFullName">Requester Name</option>
<option value="PhysicalServerName">Server Name</opton>
<option value="Create_Date">Create Date</optiuon>
&nbsp;
</select>
Search: <input name="searchtxt" type="text">
<input type="submit" name="dosearch" value="Search">
</form></td></tr><b>
</table>

NO ERRORS , but please point out any problems i may here if you see it, thanks. Im stuck on the search.php file. Should i do a conditional statement, case or function. 2nd im not sure how the SQL query will be. Im using odbc to connect. Next the php file

search.php
Here is a copy of the code , just a snipet its reporting an error of

Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in "'""search.php on line 19

#Form Execution and Results
if($_GET['drpdb']=="RequesterFullName"){
$qa="SELECT RequesterFullName, Create_Date FROM Storage_Request WHERE RequesterFullName LIKE $_GET["searchtxt"]' ";
$result=odbc_exec($conn,$qa);
}
while(odbc_fetch_row($result)){
$RequesterFullName = odbc_result_all($result, 1);
$Create_Date = odbc_result_all($result, 2);
print("$RequesterFullName $Create_Date\n");

else if($_GET['drpdb']=="PhysicalServerName"){
$qb="SELECT PhysicalServerName , Create_Date FROM Storage_Request WHERE PhysicalServerName LIKE '($_GET['searchtxt'])' ";
$result=odbc_exec($conn,$qb);
}
while(odbc_fetch_row($result)){
$PhysicalServerName = odbc_result_all($result, 1);
$Create_Date = odbc_result_all($result, 2);
print("$PhysicalServerName $Create_Date\n");

}
?>

As you can see there a 2 different sql statements im trying, neither works. Line 19 is bolded. What is wrong with my sql query? Should i use conditionals to accomplish this? How do i display it, any help will be appreciated and thanks.

Re: search form using php HELP

Posted: Wed Aug 11, 2010 7:48 pm
by califdon
PHP does not expand expressions within double-quoted strings. You have to concatenate like this:

Code: Select all

$qa="SELECT RequesterFullName, Create_Date FROM Storage_Request WHERE RequesterFullName LIKE" . $_GET["searchtxt"] . "'";
You probably want to have a % wildcard in there, too.

Re: search form using php HELP

Posted: Tue Aug 17, 2010 8:01 am
by newtoprograming1221
thanks cali, can you tell me why now i am not able to completely display the query? I have 2 issues now, any ideas???

1. when displaying results; always minus 1 record, so if had 6 entries in the table or results will only show 5,
2. cannot search for only 1 entry/record in the database eventhough i know it exist. that happens to all my searches no matter which criteria the user selects.
"no rows found" is the error messages. Lets just say there really is no data found in the database like a dummy search "dfdfdfdfd" it will spit out "No records found", which i coded in so there is a difference in telling if there is really a record found or not.

Code: Select all

$sdrp = $_POST["drpdb"];

if ($sdrp =="AppRequestID" && $stxt != null) {
     $query="SELECT AppRequestID, RequesterFullName, Create_Date, Capacity_Status, Workorder_status FROM ILM_Storage_Request_MAIN3 WHERE AppRequestID LIKE '%$stxt%'  ORDER BY Create_Date DESC";
	 $result = odbc_exec($conn,$query);
	 print " You are Searching for : Work Order $stxt";
     while(odbc_fetch_row($result)) {
	$appid = odbc_result_all($result);
	print("$appid ");
	exit;
	}
on top is a snipet of the code but the meat of the query for each criteria a user select from a drop down and types in a search text form. thanks for your help

Re: search form using php HELP

Posted: Tue Aug 17, 2010 1:20 pm
by califdon
For future reference, please use [ syntax=php] and [ /syntax] tags around PHP code that you include in a post on this forum. It will make it much easier for us to read. (Don't include the spaces)

You are using PHP functions that I have never used, the odbc_... functions, so I'm not familiar with them. But when I looked up odbc_result_all in the manual, it says "Prints all rows from a result identifier produced by odbc_exec(). The result is printed in HTML table format." So I think that you should not use that function within the while(odbc_fetch_row($result)) loop. I think what is happening is that odbc_fetch_row() moves to the first row, so your odbc_result_all begins with the second row. That would also explain why searches don't report anything, since your code doesn't do anything with the first row.

Try removing the while(odbc_fetch_row($result)) loop completely and just use the odbc_result_all() function, if you just want to display the results in an HTML table format.