Hello Every One.

i have a database name products
id
Pr_name
price etc

I want auto complete script that they retrive product name from (Pr_name).
i want that my search enging display auto name from my database.

This is my Search Code:

<div id="wb_Form2" style="position:absolute;width:483px;height:112px;">
<form name="search" method="get" action="db1.php" id="Form2" onsubmit="return Validatesearch(this)">
<input type="text" id="Editbox8" style="position:absolute;left:11px;top:17px;width:456px;height:38px;line-height:38px;z-index:18;" name="query" value="" autocomplete="off" input type="text" name="query">
<input type="submit" id="Button3" name="" value="Add" style="position:absolute;left:192px;top:71px;width:96px;height:37px;z-index:19;">
</form>
</div>
Member Avatar

diafol

So what do you want? You want us to write code for you? Where's your code?

This is my Search Code:

That's not code, it's markup, and use CSS if possible instead of inline styling. If you post your php code, we can have a look at it.

Thats my search code.
i have one other code which is for print search data.

Member Avatar

diafol

Like I said, that's markup, not 'code'. It doesn't actually do anything, just display a searchbox/button. I'm referring to your php/mysql code. Where's that? That's what we need to see in order to help you with any difficulties that you may be experiencing.

So, post your code...

i didn't have any code thats why i need help..

Member Avatar

diafol

Well, this is a help forum, but it's mainly to help you with your own code. It's not expected of contributors to write code from scratch.

How about you look at the php.net manual or look at some online php tutorials to get started? There are hundreds of tutes out there.

here's a starter for mysqli to make a db connection: http://uk3.php.net/manual/en/mysqli.construct.php

This is my search code ....

<html>
<body>
<head>
<font size="3"><strong>
<?php // Connects to your Database 
    mysql_connect("host", "user", "pass") or die(mysql_error());
    mysql_select_db("table") or die(mysql_error());
$q = mysql_real_escape_string($_GET['query']);
$data = mysql_query("SELECT * FROM Products where name LIKE '%$q%'")
    or die(mysql_error()); 
    while($info = mysql_fetch_array( $data ))
    { 
echo "Product Name: $info[name]<br>";
echo "Good Price: $info[good]<br>";
echo "Poor Price: $info[poor]<br>";
echo "Faculty Price: $info[faulty]<br><br>";
    } 
    ?>

does the above code give you results..?
i mean does it output product name, good price, ... etc?

if not could it be mysql_select_db("table") or die(mysql_error());
you should have database name where you written table?

my prob is just auto complete or suggestion in search blank

Member Avatar

diafol

There are loads of scripts available online, without having to write one from scratch (or ask contributors to write one) - e.g. http://www.htmlblog.us/jquery-autocomplete

Googled: "autocomplete php mysql"

Thanks diafol, the link you provided was useful

Member Avatar

diafol

it didn't show anything

What didn't? The tutorials were not whta you wanted or you couldn't get the scripts to work?
Unless you post your updated code with errors/problems, we don't know what you're trying.

Thgis is Scripts:

autocompletemain.php

<?php
$host="host.com"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name


    $con = mysql_connect($host,$username,$password)   or die(mysql_error());
    mysql_select_db($db_name, $con)  or die(mysql_error());

$q = strtolower($_GET["q"]);
if (!$q) return;

$sql = "select Products name as name from name where name LIKE '%$q%'";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
    $cname = $rs['name'];
    echo "$cname\n";
}
?>

And Form

<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<title>jQuery Autocomplete Plugin</title>
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />

<script type="text/javascript">
$().ready(function() {
    $("#course").autocomplete("autoCompleteMain.php", {
        width: 260,
        matchContains: true,
        //mustMatch: true,
        //minChars: 0,
        //multiple: true,
        //highlight: false,
        //multipleSeparator: ",",
        selectFirst: false
    });
});
</script>
</head>
<body>
<h2 id="banner">Autocomplete using jQuery, Ajax, PHP</h1>
<div id="content">
    <form autocomplete="off">
        <p>
            Enter Language Name <label>:</label>
            <input type="text" name="name" id="name" />
        </p>
        <input type="submit" value="Submit" />
    </form>
</div>
</body>
</html>
Member Avatar

diafol

Have you tried out a dummy page with this script, e.g.

In your php page, just have:

<?php

echo "boo\nfoo\nbar";

?>

Also, look at the console to see if you have any js issues. If using Chrome, this can be found with right-click > 'Inspect element' > 'Console'

Member Avatar

diafol

OK you're problem seems to be the php/mysql then. Fix it and it should work.

no prob there i re chked it 2 times

Member Avatar

diafol

so if autocomplete js is working with hard coded php and your php/mysql is working (tested by you), sorry I'm lost, can't see any reason why your code won't work.

  1. there is difference in the name of the file.While calling "M" is capital of autocompletemain.php

    $("#course").autocomplete("autoCompleteMain.php", {
    
  2. 2nd problem is of the id "course" that you are using

    Instead of "course" ,it should be the id of textbox i.e,"name".

    Replace this,

     $("#course").autocomplete("autoCompleteMain.php", {
    

    with

     $("#name").autocomplete("autoCompleteMain.php", {
    

    Replace the two problems,and hope autocomplete is working.If still there is problem do ask along with the error.

Also keep note of first point.Either change file name or change it here.

thankx for your suggestions prob was in database. but here is some ting that you gyz provide help.

i hhave my own form this is code: (searchform.php)

<div id="wb_Form2" style="position:absolute;width:483px;height:112px;">
<form name="search" method="get" action="db1.php" id="Form2" onsubmit="return Validatesearch(this)">
<input type="text" id="Editbox8" style="position:absolute;left:11px;top:17px;width:456px;height:38px;line-height:38px;z-index:4;" name="query" value="" autocomplete="off" input type="text" name="query">
<input type="submit" id="Button3" name="" value="Add" style="position:absolute;left:192px;top:71px;width:96px;height:37px;z-index:5;">
</form>
</div>

And this is jave script form (javascript.php)

<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<title>Autocomplete</title>
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />

<script type="text/javascript">
$().ready(function() {
    $("#name").autocomplete("autoCompleteMain.php", {
        width: 260,
        matchContains: true,
        //mustMatch: true,
        //minChars: 0,
        //multiple: true,
        //highlight: false,
        //multipleSeparator: ",",
        selectFirst: false
    });
});
</script>
</head>
<body>
<h2 id="banner">Autocomplete</h1>
<div id="content">
    <form autocomplete="off">
        <p>
            Enter Product Name <label>:</label>
            <input type="text" name="name" id="name" />
        </p>
        <input type="submit" value="Submit" />
    </form>
</div>
</body>
</html>

My Prob is i want to implement my autosearch java function into my own form code (searchform.php)