1

I'm a newbie on php, javascript and ajax. I got this tutorial about How to Create a Search Feature with PHP and MySQL and it was a success after creating it. Link: http://www.webreference.com/programming/php/search/index.html

Now I'm changing the index.html file and linked only to search_display.php file for just a simple price checker program. I was confuse on how to link the "code" result under Javascript function doScan(code) to search_display.php.

<script>
   function doScan(code) //displays the value target after scanning.
   {
      divStatus.innerHTML = 'Scanned Code:<br>&nbsp;&nbsp;' + code;
      setTimeout("startScanner()", 1250);
   }
</script>

I wanted to link "code" to search_display.php and this is the code:

<?php
  if(isset($_POST['submit'])){
  if(isset($_GET['go'])){
  //if(preg_match("/^[a-zA-Z]+/", $_POST['name'])){
  $name=$_POST['name'];
  //connect to the database
  $db=mysql_connect("localhost", "root", "bbp0m") or die ('I cannot connect to the database  because: ' . mysql_error());
  //var_dump($db);
  //-select the database to use
  $mydb=mysql_select_db("price_checker");
  //var_dump($mydb);
  //-query the database table
  $sql="SELECT * FROM stock_master WHERE gtin LIKE '%" . @$name .  "%'";
  //var_dump($sql);
  //-run the query against the mysql query function
  $result=mysql_query($sql);
  //var_dump($result);
  //-create while loop and loop through result set
  while($row=mysql_fetch_array($result)){
          $itemcode=$row['itemcode'];
          $desc1=$row['desc1'];
          $desc2=$row['desc2'];
          $uom=$row['uom'];
          $gtin=$row['gtin'];
          $retailprice=$row['retailprice'];
  //-display the result of the array
  echo "<ul>\n";
  echo "<li>" . "<a  href=\"index.html?id=$gtin\">" .$itemcode . " " . $desc1 . " " . $desc2 . " " . $uom . " " . $gtin . " " . $retailprice . "</a></li>\n";
  echo "</ul>";
  }
  }
  else{
  echo  "<p>Please enter a search query</p>";
  }
  }
  //}
?>

Any ideas how to link it and if possible I would like to put everything into index.html?

Bert

4
  • You should make an AJAX request to the PHP code from your HTML page. You also should update your driver from mysql_ to PDO or mysqli and use prepared statements. Commented Dec 14, 2015 at 2:59
  • How? i'm confused placing this unset variable "code". Perhaps you could place an example? Please go easy on me Chris. I'm learning as much as I can... Commented Dec 14, 2015 at 3:28
  • Take a look at some tutorials or maybe, stackoverflow.com/questions/15780031/…. If you have a specific question please ask that. Commented Dec 14, 2015 at 3:33
  • Sorry Chris i just realize that it return to div id global attributes but I do not know the approach of getting the that line result <div id="bcode"></div> I wanted to know now how to link that statement to the search_display.php? Do you have any ideas? Commented Dec 15, 2015 at 22:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.