Jump to content

Recommended Posts

hey

I need this to connect to my database on my sybase sql server, but no matter what i try, it won't populate the plunum field. Any help would be appreciated. 

 

Here is my HTML code:

 

<html>
<head>
    <title>helloscan</title>
          <meta http-equiv="refresh" content="18">        
          <meta http-equiv="scanner" content="javascript:doScan('%s');"/>
          <meta http-equiv="scanner" content="start"/>
          <META HTTP-Equiv="scanner" Content="enabled" />
          <META HTTP-Equiv="scanner" Content="AutoEnter:Enabled"/>
          <meta http-equiv="keycapture" content="accelerate:all" />
          <meta http-equiv="keycapture" content="keyvalue:0x0D; dispatch=true; keyevent:url('javascript:mykeypressed();')" />         
          <meta http-equiv="quitbutton" content="visibility: visible;"/>       
    <script language="javascript" type="text/javascript">
      function doScan(data){
          var divEl = ("%s");       
      }
      function enablescanner(enable){
         Generic.InvokeMetaFunction('scanner', 'start');
         Generic.InvokeMetaFunction('scanner', 'enabled');
         Generic.InvokeMetaFunction('scanner', 'autoenter:enabled');
      }
      </script>
      <script>
      function get_plunum(){
         xmlhttp=ajaxfunction();
         if (xmlhttp==null) {
            alert ("no ajax support");
            return;
         }
         var ae_xrefnum = document.getelementbyid('ae_xrefnum').value;
         var ae_plunum = document.getelementbyid('ae_plunum').value;
         var querystring = "?ae_xrefnum=" + xrefnum + "&ae_plunum="+ plunum";
         xmlhttp.onreadystatechange = function (){
            if (xmlhttp.readystate == 4 || xmlhttp.readystate=="comlete"){
                   document.myform.ae_plunum.value = xmlHttp.responseText;
         }
      }
      xmlhttp.open("GET", "helloscan2.php"+querystring, true);
      xmlhttp.send(null);
      }
      function ajaxfunction(){
        var xmlhttp=null;
        try {// code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp=new XMLHttpRequest();
        }
        catch (err) {// code for IE6, IE5
           xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        return xmlhttp;
      }            
     </script>
</head>
<body  onload="enablescanner(true)">
    <h3 align="center"><center><img src="ac moore" /></center>Please scan a barcode...</h3>
    <form  name="myform">
    ItemBarcode:
    <input type="text" id="ae_xrefnum" name="ae_xrefnum" itembarcode="divE1" oninput="get_plunum()" /> 
    plunum:
    <input type="text" id="ae_plunum" name"ae_plunum" oninput="get_price()"/>
    </form>
    <script language=javascript>
        {
          document.myform.ae_xrefnum.focus();
        }
    </script>
</body>
</html>

 

And Here is my PHP code:

 

<?php
//================================================================

  // Configure connection parameters
  $db_host        = "97.0.40.244, 1498";
  $db_server_name = "ACMSQL036A";
  $db_name        = "backoff.db";
  $db_file        = 'd:\trvbkup\DB';
  $db_conn_name   = "php_script";
  $db_user        = "dba";
  $db_pass        = "sql";

//================================================================
  $connect_string = "Driver={Adaptive Server Anywhere 8.0};".
                    "CommLinks=tcpip(Host=$db_host);".
                    "ServerName=$db_server_name;".
                    "DatabaseName=$db_name;".
                    "DatabaseFile=$db_file;".
                    "ConnectionName=$db_conn_name;".
                    "uid=$db_user;pwd=$db_pass";

  // Connect to DB
  $conn = odbc_connect($connect_string,'','');

  // Query
  $qry = "SELECT xrefnum, plunum FROM DBA.PLU_Cross_Ref where xrefnum = '$xrefnum'";

  // Get Result
  $result = odbc_exec($conn,$qry);

  // Get Data From Result
  while ($row[] = odbc_fetch_array($result));

  // Free Result
  odbc_free_result($result);

  // Close Connection
  odbc_close($conn);

  // Show data
  print_r($row[plunum]);

//================================================================
?>

Link to comment
https://forums.phpfreaks.com/topic/237005-connect-to-sql-database/
Share on other sites

1) What happens?  Do you get an error?  Where does the script break?  What have you done to isolate the issue so that we don't have to go through your entire codes.

2) In the future, please place


tags around your code.

3) If you're having trouble connecting to the DB then it's most likely a PHP issue, I'll move it to that section.

1) What happens?  Do you get an error?  Where does the script break?  What have you done to isolate the issue so that we don't have to go through your entire codes.

2) In the future, please place


tags around your code.
3) If you're having trouble connecting to the DB then it's most likely a PHP issue, I'll move it to that section.

yea sorry about that, never used forums before, but i've run out of options as no one i work with knows enough about html, javascript, and php to help me complete this, so i figured i'd ask a community online.

Well i know everything in the html works fine, what i'm concerned about is part
  <script>
      function get_plunum(){
         xmlhttp=ajaxfunction();
         if (xmlhttp==null) {
            alert ("no ajax support");
            return;
         }
         var ae_xrefnum = document.getelementbyid('ae_xrefnum').value;
         var ae_plunum = document.getelementbyid('ae_plunum').value;
         var querystring = "?ae_xrefnum=" + xrefnum + "&ae_plunum="+ plunum";
         xmlhttp.onreadystatechange = function (){
            if (xmlhttp.readystate == 4 || xmlhttp.readystate=="comlete"){
                   document.myform.ae_plunum.value = xmlHttp.responseText;
         }
      }
      xmlhttp.open("GET", "helloscan2.php"+querystring, true);
      xmlhttp.send(null);
      }
      function ajaxfunction(){
        var xmlhttp=null;
        try {// code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp=new XMLHttpRequest();
        }
        catch (err) {// code for IE6, IE5
           xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        return xmlhttp;
      }            
     </script>

 

Through all my research, this seems like it's sound, but i think it's either not calling on my php script,  processing my querystring, or i'm just not connecting to my db

 

// Query
  $qry = "SELECT xrefnum, plunum FROM DBA.PLU_Cross_Ref where xrefnum = '$xrefnum'";

  // Get Result
  $result = odbc_exec($conn,$qry);

  // Get Data From Result
  while ($row[] = odbc_fetch_array($result));

  // Free Result
  odbc_free_result($result);

  // Close Connection
  odbc_close($conn);

  // Show data
  print_r($row[plunum]);

 

See what i'm trying to do here is query  ae_xrefnum from my sybase sql db through an odbc connection, and from that query autopopulate ae_plunum

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.