Page 1 of 1

Search box

Posted: Wed Jul 15, 2009 12:15 pm
by perfect123
I was wondering if you can give a tutorial to how you can insert a search box results in a text box.
I have created a search box which potentially works. But I wish to insert the results in to the text box rather than having them on a new page.

I have a text box called ref and a search button next to it. so When I put in a search and click search, the results should appear in the ref text box. I hope you understand what I mean. I know you have to define a variable and assign it to the text box, but the question is how> please help.

Ive been trying to solve this for hours now


<?
$myServer = 'learoyd-sql';
$myUser = 'sa';
$myPass = '25141260';
$myDB = 'CompanyL';
$SpecRef = $_GET['query'];
print ("$SpecRef");



//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");

<form action="search.php" method="get">
<input type="text" name="query" id="query" size="40" value="" action="include/js_suggest/suggest.php" columns="2" autocomplete="off" delay="1500" />
<input type="submit" value="Search">
<input type="hidden" name="search" value="1">
</form>
<center><a href="search2.php?adv=1">Advanced search</a></center>
</div>


//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
//error message (not found message)begins
$XX = "No Matches Found";
//query details table begins
$query = ("SELECT * FROM dbo.DesignControl WHERE Spec_Ref LIKE'$SpecRef%' ");
// $query = ("SELECT * FROM dbo.DesignProcess");

print('$query');


//execute the SQL query and return records
$result = mssql_query($query);

$numRows = mssql_num_rows($result);
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";

//display the results
while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["Spec_Ref"] . "</li>";
}
//close the connection
mssql_close($dbhandle);

/*while ($row = @mysql_fetch_array($query))
{
$variable1=$row["Player"];
$variable2=$row["Avg"];
$variable3=$row["HR"];
$variable4=$row["RBI"];
//table layout for results

print ("<tr>");
print ("<td>$variable1</td>");
print ("<td>$variable2</td>");
print ("<td>$variable3</td>");
print ("<td>$variable4</td>");
print ("</tr>");
}
//below this is the function for no record!!

if (!$variable1)
{
print ("$XX");
}
//end */
?>

Re: Search box

Posted: Wed Jul 15, 2009 12:57 pm
by andyhoneycutt
A couple of things: First- I really hope the credentials you are posting on the page for your mssql connect aren't the ones you use for production, if so, obfuscate dude. We don't need that information, and you don't want that information to be public knowledge. Secondly, please post your code references in

Code: Select all

blocks, it makes it a lot easier to read.

I wasn't aware you could assign an action to a form element, I thought the action resided only in the form itself?

-Andy