mrdav30 Posted May 26, 2011 Share Posted May 26, 2011 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); //================================================================ ?> Quote Link to comment Share on other sites More sharing options...
Maq Posted May 26, 2011 Share Posted May 26, 2011 AFAIK, it doesn't matter. Why, do they act differently in your code? Quote Link to comment Share on other sites More sharing options...
mrdav30 Posted May 26, 2011 Author Share Posted May 26, 2011 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? Quote Link to comment Share on other sites More sharing options...
mgoodman Posted May 26, 2011 Share Posted May 26, 2011 // Get Data From Result $row=odbc_fetch_array($result); // Show data print($row[plunum]); } Why's there a random } there? I think that might be your problem. Quote Link to comment Share on other sites More sharing options...
Maq Posted May 26, 2011 Share Posted May 26, 2011 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); Quote Link to comment Share on other sites More sharing options...
xyph Posted May 26, 2011 Share Posted May 26, 2011 He meant mysql_real_escape_string() Though it's a mysql function, it should work fine sanitizing for odbc. Quote Link to comment Share on other sites More sharing options...
mrdav30 Posted May 26, 2011 Author Share Posted May 26, 2011 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. Quote Link to comment Share on other sites More sharing options...
xyph Posted May 26, 2011 Share Posted May 26, 2011 I don't see any PHP attempting to fill those forms. Quote Link to comment Share on other sites More sharing options...
mrdav30 Posted May 26, 2011 Author Share Posted May 26, 2011 well that might be my problem because i though that document.myform.ae_plunum.value = xmlHttp.responseText; would take the output from print and fill it in, but then again i'm a noob when it comes to php so any suggestions of what i would do to accomplish this? Quote Link to comment Share on other sites More sharing options...
xyph Posted May 26, 2011 Share Posted May 26, 2011 helloscan2.php isn't being given any variables $xrefnum = $_GET['ae_xrefnum']; try using helloscan2.php?ae_xrefnum=some_data Quote Link to comment Share on other sites More sharing options...
mrdav30 Posted May 26, 2011 Author Share Posted May 26, 2011 would this work then? var ae_xrefnum = document.getelementbyid('ae_xrefnum').value; var querystring = "?ae_xrefnum=" + ae_xrefnum; xmlhttp.open("GET", "helloscan2.php" + querystring, true); xmlhttp.send(null); Quote Link to comment Share on other sites More sharing options...
mrdav30 Posted May 26, 2011 Author Share Posted May 26, 2011 thanks for all your help guys!, almost done Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.