Jump to content

print or echo?


mrdav30

Recommended Posts

Should i be using print() or echo() for an xmlhttp.responsetext ?

 

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

  // Configure connection parameters
  $connect_string="DRIVER={Sybase SQL Anywhere 5.0}; SERVER=ACMSQL036A; DATABASE=BACKOFF";
  $dbuser="DBA"
  $dbpswd="SQL"

//================================================================

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


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

  // Get Result
  $result = odbc_exec($conn,$qry);
  if (!$result)
  {
   echo odbc_errormsg($conn);
  }

  // Get Data From Result
  $row=odbc_fetch_array($result);
  
  // Show data
  print($row[plunum]);
  }

  // Free Result
  odbc_free_result($result);

  // Close Connection
  odbc_close($conn);

  

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

Link to comment
https://forums.phpfreaks.com/topic/237549-print-or-echo/
Share on other sites

wasn't sure, b/c neither of them would populate my form field.  Is my $qry correct? can i take the plunum next to the xrefnum  in the table where xrefnum was equal to $xrefnum and only print that plunum out?

- First of all, your code does not populate a form field as far as I can see.  Does your print statement output anything?

- You should be sanitizing any input to the database with mysql_real_escape_query to prevent sql injections.

- You have an extra terminating '}' here, but no starting one (fatal error):

  // Show data
  print($row[plunum]);
  }

- Your query looks valid, although I can't guarantee that it's correct.  If you are seeing a blank screen it's because you have the fatal error I mentioned above.  Fix it and put these 2 lines directly under your opening <?php tag to detect further errors:

ini_set ("display_errors", "1");
error_reporting(E_ALL);

Link to comment
https://forums.phpfreaks.com/topic/237549-print-or-echo/#findComment-1220711
Share on other sites

hey thanks for the help so far guys, yea i've been using netpanel and i noticed the errors you guys where talking about doing that.

 

wasn't sure, b/c neither of them would populate my form field.  Is my $qry correct? can i take the plunum next to the xrefnum  in the table where xrefnum was equal to $xrefnum and only print that plunum out?

- First of all, your code does not populate a form field as far as I can see.  Does your print statement output anything?

- You should be sanitizing any input to the database with mysql_real_escape_query to prevent sql injections.

- You have an extra terminating '}' here, but no starting one (fatal error):

  // Show data
  print($row[plunum]);
  }

- Your query looks valid, although I can't guarantee that it's correct.  If you are seeing a blank screen it's because you have the fatal error I mentioned above.  Fix it and put these 2 lines directly under your opening <?php tag to detect further errors:

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

The form i'm trying to populate with print is in this code here:

<html>
<head>
    <title>helloscan</title>
          <!--refreshes page in seconds-->
          <meta http-equiv="refresh" content="50">
          <!--produces barcode number and make var-->        
          <meta http-equiv="scanner" content="javascript:doScan('%s');"/>
          <!--following enables scanner-->
          <meta http-equiv="scanner" content="start"/>
          <META HTTP-Equiv="scanner" Content="enabled" />
          <!--adds enter to end of barcode allowing keyevent to occur-->
          <META HTTP-Equiv="scanner" Content="autoenter:enabled" />
          <META HTTP-Equiv="keycapture" content="acceleratekey:all" />
          <META HTTP-Equiv="keycapture" content="keyvalue:0x0D; keyevent:'javascript:get_plunum()'" /> 
          <!--puts quitbutton near top right, for development-->       
          <meta http-equiv="quitbutton" content="visibility: visible;"/>       
    <script language="javascript" type="text/javascript">
    //produces variable for ae_xrefnum
      function doScan(data){
          var divEl = ("%s");
      }
      //on refresh, allows scanner to come back up
      function enablescanner(enable) {
         Object.InvokeMetaFunction('scanner', 'start');
         Object.InvokeMetaFunction('scanner', 'enabled');
         Object.InvokeMetaFunction('scanner', 'autoenter:enabled');
         }  
      </script>
      <script language="javascript" type="text/javascript">
      //called from meta tag after autoenter attached to scan, checks to make sure ajax active, then send out query for ae_xrefnum
      function get_plunum(){
          try {// code for IE7+, Firefox, Chrome, Opera, Safari
              xmlhttp = new XMLHttpRequest();
          }
          catch (err) {// code for IE6, IE5
              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          }
          return xmlhttp;
          }    
          //sends to php to query
          var ae_xrefnum = document.getelementbyid('ae_xrefnum').value;
          xmlhttp.open("GET", "helloscan2.php", true);
          xmlhttp.send(null);     
          xmlhttp.onreadystatechange = function query() {
         //receives data from server, and puts repsonse in ae_plunum field
            if (xmlhttp.readystate == 4 && xmlhttp.status=="complete"){
                   document.myform.ae_plunum.value = xmlHttp.responseText;
          }
          }            
     </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" /> 
    plunum:
    <input type="text" id="ae_plunum" name"ae_plunum" oninput="get_price()"/>
    <!--button here for development-->
    <input type="submit" id="submitbtn" value="submit me" onsubmit="get_plunum" />
    </form>
    <script language=javascript>
    //focuses on ae_xrefnum when refresh occurs or page loads
        {
          document.myform.ae_xrefnum.focus();
        }
    </script>
</body>

 

i'm trying to populate the ae_plunum field with that print output.

Link to comment
https://forums.phpfreaks.com/topic/237549-print-or-echo/#findComment-1220719
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.