New at this ..Question using with php
I am new at this so this might seem like a stupid question. How do I pass the value in my auto complete text box to my php script ? (see code below).
index.html
- <!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>Ajax Auto Suggest</title>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/
- libs/jquery/1.3.0/jquery.min.js"></script>
- <script type="text/javascript">
- function lookup(inputString) {
- if(inputString.length == 0) {
- // Hide the suggestion box.
- $('#suggestions').hide();
- } else {
- $.post("rpc.php", {queryString: ""+inputString+""}, function(data){
- if(data.length >0) {
- $('#suggestions').show();
- $('#autoSuggestionsList').html(data);
- }
- });
- }
- } // lookup
-
- function fill(thisValue) {
- $('#inputString').val(thisValue);
- setTimeout("$('#suggestions').hide();", 200);
- }
- </script>
- <style type="text/css">
- body {
- font-family: Helvetica;
- font-size: 11px;
- color: #000;
- }
-
- h3 {
- margin: 0px;
- padding: 0px;
- }
- .suggestionsBox {
- position: relative;
- left: 30px;
- margin: 10px 0px 0px 0px;
- width: 200px;
- background-color: #212427;
- -moz-border-radius: 7px;
- -webkit-border-radius: 7px;
- border: 2px solid #000;
- color: #fff;
- }
-
- .suggestionList {
- margin: 0px;
- padding: 0px;
- }
-
- .suggestionList li {
-
- margin: 0px 0px 3px 0px;
- padding: 3px;
- cursor: pointer;
- }
-
- .suggestionList li:hover {
- background-color: #659CD8;
- }
- </style>
- </head>
- <body>
- <div>
- <Form action="insert_new_number.php" method="POST">
- <div>
- Company Code:
- <br />
- <input type="text" size="30" value="" id="inputString" name="custid" onkeyup="lookup(this.value);" onblur="fill();" />
- </div>
-
- <div class="suggestionsBox" id="suggestions" style="display: none;">
- <img src="upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
- <div class="suggestionList" id="autoSuggestionsList">
-
- </div>
- </div>
- <input type="submit" />
- </form>
- </div>
- </body>
- </html>
RPC.php
- <?php
-
- // PHP5 Implementation - uses MySQLi.
- // mysqli('localhost', 'yourUsername', 'yourPassword', 'yourDatabase');
- $db = new mysqli('localhost', 'xxxxxxx' ,'xxxxxxxx', 'xxxxxxx');
-
- if(!$db) {
- // Show error if we cannot connect.
- echo 'ERROR: Could not connect to the database.';
- } else {
- // Is there a posted query string?
- if(isset($_POST['queryString'])) {
- $queryString = $db->real_escape_string($_POST['queryString']);
-
- // Is the string length greater than 0?
-
- if(strlen($queryString) >0) {
-
- $query = $db->query("SELECT Customer_Code FROM data WHERE Customer_Code LIKE '$queryString%' LIMIT 10");
- if($query) {
-
- while ($result = $query ->fetch_object()) {
-
- echo '<li onClick="fill(\''.$result->Customer_Code.'\');">'.$result->Customer_Code.'</li>';
-
- }
- } else {
- echo 'ERROR: There was a problem with the query.';
- }
- } else {
- // Dont do anything.
- } // There is a queryString.
- } else {
- echo 'There should be no direct access to this script!';
- }
- }
- ?>
insert_new_number.php is the script I want to send the data to, from the ajax auto complete text box. I just can't figure out how to do it.
Thanks