Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7746721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:21:03+00:00 2026-06-01T10:21:03+00:00

I have a user form that is working perfectly. The page makes use of

  • 0

I have a user form that is working perfectly. The page makes use of a javascript script that executes mysql query from an external php file and displays the results on the table.

What I want to do is have the ability to display results from mulitple different queries on the form as well.

I have 4 files in this example.
test.php which is the form
getdata1.php which fetches mysql results for product information
getwhse1.php which fetches mysql results for warehouse information
getsu1.php which fetches mysql results for selling units information

Currently the script works when just fetching results from getdata1.php? How do I alter the javascripscript to allow me to display results from getwhse1.php and getsu1.php as well?

Below is the code for the existing pages, what I want to be able to do is enter a product code and display the details of that product code in each of the table fields.

test.php

<html>
<head>
<title>Sales Portal</title>
<script type="text/javascript"> 
  function showUser(userNumber, str) 
  { 
    if (str=="") 
    { 
      document.getElementById("txtHint" + userNumber).innerHTML=""; 
      return; 
    }   
    if (window.XMLHttpRequest) 
    {// code for IE7+, Firefox, Chrome, Opera, Safari 
      xmlhttp=new XMLHttpRequest(); 
    } 
    else 
    {// code for IE6, IE5 
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    } 

    xmlhttp.onreadystatechange=function() 
    { 
      if (xmlhttp.readyState==4 && xmlhttp.status==200) 
      { 
        document.getElementById("txtHint" + userNumber).innerHTML=xmlhttp.responseText; 
      } 
    } 
    xmlhttp.open("GET","getdata1.php?q="+str,true); 
    xmlhttp.send(); 
  }
</script>

</head>
<body topmargin=0>

<form name="orderform" id="orderform" action="newsale.php" method="post">

<table border=1>    

<tr>
<td>Product Code</td>
<td>Description</td>
<td>Warehouse</td>
<td>Selling Units</td>
</tr>
<tr id="r1">  
    <td width=100>
        <input size=10  type=number id=sku1 name=sku1 onchange="showUser(1, this.value)">
    </td>
    <td width=280>
        <div align="left" id="txtHint1">&nbsp;</div>
    </td>
    <td width=100>
        <div align="left" id="whse1">&nbsp;</div>
    </td>
    <td width=100>
        <div align="left" id="su1">&nbsp;</div>
    </td>
</tr>
<tr id="r2">  
    <td>
        <input size=10  type=number id=sku2 name=sku2 onchange="showUser(2, this.value)">
    </td>
    <td>
        <div align="left" id="txtHint2">&nbsp;</div>
    </td>
    <td>
        <div align="left" id="whse2">&nbsp;</div>
    </td>
    <td width=100>
        <div align="left" id="su2">&nbsp;</div>
    </td>
</tr>
<tr id="r3">  
    <td>
        <input size=10  type=number id=sku3 name=sku3 onchange="showUser(3, this.value)">
    </td>
    <td>
        <div align="left" id="txtHint3">&nbsp;</div>
    </td>
    <td>
        <div align="left" id="whse3">&nbsp;</div>
    </td>
    <td width=100>
        <div align="left" id="su3">&nbsp;</div>
    </td>
</tr>
<tr id="r4">  
    <td>
        <input size=10  type=number id=sku4 name=sku4 onchange="showUser(4, this.value)">
    </td>
    <td>
        <div align="left" id="txtHint4">&nbsp;</div>
    </td>
    <td>
        <div align="left" id="whse4">&nbsp;</div>
    </td>
    <td width=100>
        <div align="left" id="su4">&nbsp;</div>
    </td>
</tr>
</table>
</form>

</body>
</html>

getdata1.php

<?php
 $q=$_GET["q"];

$con = mysql_connect('localhost', 'username', 'password');
 if (!$con)
   {
   die('Could not connect: ' . mysql_error());
   }

mysql_select_db("dbname", $con);


$sql="SELECT Category, Description,SellingUnits,Grouping,CasesPerPallet,ShrinksPerPallet FROM skudata WHERE packcode = '".$q."'";
$result = mysql_query($sql);
$rows=mysql_num_rows($result);

if($rows==0){echo "<font color=red><b>NOT A VALID PRODUCT CODE</b></font>";} else {
while($row = mysql_fetch_array($result))
   {
   echo "<font color=red>".$row['Description']."</font>, ";
   if($row['SellingUnits']=="CS"){echo "<font color=red>".$row['CasesPerPallet']."</font> ";} elseif($row['SellingUnits']=="SHR") {echo "<font color=red>".$row['ShrinksPerPallet']."</font> ";}
   }}

mysql_close($con);
 ?> 

getwhse1.php

<?php
 $q=$_GET["q"];

$con = mysql_connect('localhost', username', 'password');
 if (!$con)
   {
   die('Could not connect: ' . mysql_error());
   }

mysql_select_db("database", $con);

$sql="SELECT grouping FROM skudata WHERE packcode = '".$q."'";
$result = mysql_query($sql);
$rows=mysql_num_rows($result);

if($rows==0){echo "&nbsp;";} else {
while($row = mysql_fetch_array($result))
   {
   echo "<font color=red>".$row['grouping']."</font>, ";
   }}

mysql_close($con);
 ?> 

getsu1.php

<?php
 $q=$_GET["q"];

$con = mysql_connect('localhost', 'username', 'password');
 if (!$con)
   {
   die('Could not connect: ' . mysql_error());
   }

mysql_select_db("database", $con);

$sql="SELECT SellingUnits  FROM skudata WHERE packcode = '".$q."'";
$result = mysql_query($sql);
$rows=mysql_num_rows($result);

if($rows==0){echo "&nbsp;";} else {
while($row = mysql_fetch_array($result))
   {
   echo "<font color=red>".$row['SellingUnits ']."</font>, ";
   }}

mysql_close($con);
 ?> 

My javascript skills are non existant, how can I edit this script to execute all three mysql queries and display the results on the page? all being activated by entering a product code?

Thanks and Regards,
Ryan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:21:04+00:00Added an answer on June 1, 2026 at 10:21 am
    <?php
      $q=$_GET["q"];
      $con = mysql_connect('localhost', 'username', 'password');
     header('Content-type: application/json');
      if (!$con ||strlen($q)>5){ die(json_encode(array('results'=>-1)))}
      mysql_select_db("dbname", $con);
      $result=mysql_query("SELECT * FROM skudata WHERE packcode = '$q'");
      echo json_encode(array('results'=>$result));
     mysql_close($con);
     ?>
    
    <html><head><title>Sales Portal</title>
    <style type="text/css"> 
    .redtext {color: red}
    </style>
    <script type="text/javascript">
      function showUser(userNumber, str){ 
        if (str==""){ 
          document.getElementById("txtHint" + userNumber).innerHTML="";
        }
        if (window.XMLHttpRequest){xmlhttp=new XMLHttpRequest()}
        else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")}
        xmlhttp.onreadystatechange=function(){ 
          if (xmlhttp.readyState==4 && xmlhttp.status==200){
        var json = JSON.parse(xmlhttp.responseText);
        result = json.results;
        if(result==-1){
          document.getElementById('txtHint'+userNumber).innerHTML="Database error.";
          } 
        if(result.length = 0){
          document.getElementById("txtHint"+userNumber).innerHTML="INVALID PRODUCT CODE"; 
        }
        else {
          i=0;
          while(i<result.length){
            var desc=result[i].Description+"&nbsp;";
            switch(result[i].SellingUnits){
              case "CS": desc += result[i].CasesPerPallet+"<br/>";
              break;
              case: "SHR": desc += result[i].ShrinksPerPallet+"<br/>";
              break;
            }
            document.getElementById('txtHint'+userNumber).innerHTML = desc;
            document.getElementById('whse'+userNumber).innerHTML=result[i].grouping+"<br\>";
            document.getElementById('su'+userNumber).innerHTML=result[i].SellingUnits+"<br/>";
            i++;
          } 
          xmlhttp.open("GET","getdata1.php?q="+str,true); 
          xmlhttp.send(); 
         }
    </script>
    </head>
    <body topmargin=0>
    <form name="orderform" id="orderform" action="newsale.php" method="post">
    <table border=1>
    <tr>
    <td>Product Code</td>
    <td>Description</td>
    <td>Warehouse</td>
    <td>Selling Units</td>
    </tr>
    <tr id="r1">  
    <td width=100>
        <input size=10  type="number" id="sku1" name="sku1" onchange="showUser(1, this.value)">
    </td>
    <td width=280>
        <div align="left" id="txtHint1" class="redtext">&nbsp;</div>
    </td>
    <td width=100>
        <div align="left" id="whse1" class="redtext">&nbsp;</div>
    </td>
    <td width=100>
        <div align="left" id="su1" class="redtext">&nbsp;</div>
    </td>
    </tr>
    <tr id="r2">  
    <td>
        <input size=10  type="number" id="sku2" name="sku2" onchange="showUser(2, this.value)">
    </td>
    <td>
        <div align="left" id="txtHint2" class="redtext">&nbsp;</div>
    </td>
    <td>
        <div align="left" id="whse2" class ="redtext">&nbsp;</div>
    </td>
    <td width=100>
        <div align="left" id="su2" class="redtext">&nbsp;</div>
    </td>
    </tr>
    <tr id="r3">  
    <td>
        <input size=10  type=number id=sku3 name=sku3 onchange="showUser(3, this.value)">
    </td>
    <td>
        <div align="left" id="txtHint3" class="redtext">&nbsp;</div>
    </td>
    <td>
        <div align="left" id="whse3" class="redtext">&nbsp;</div>
    </td>
    <td width=100>
        <div align="left" id="su3" class="redtext">&nbsp;</div>
    </td>
    </tr>
    <tr id="r4">  
    <td>
        <input size=10  type=number id=sku4 name=sku4 onchange="showUser(4, this.value)">
    </td>
    <td>
        <div align="left" id="txtHint4" class="redtext">&nbsp;</div>
    </td>
    <td>
        <div align="left" id="whse4" class="redtext">&nbsp;</div>
    </td>
    <td width=100>
        <div align="left" id="su4" class="redtext">&nbsp;</div>
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    

    I haven’t tested this code but the errors should be easy to find in a browser console. The php doesn’t allow $q to be more than 5 characters to prevent injection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC 2 form that is working perfectly, doing client side
I'm working on an intermediary form that will gather some data from the user
We have a form that allows a user to filter a list with by
I have a form that and after the user fills in this form, I
I have a form that allows a user to import a spreadsheet. This spreadsheet
I have a form that enables a user to update multiple alert rules records
I currently have form that checks if a user has unsubmitted changes when they
I have a multipart form that takes basic user information at the beginning with
I have an upload form that takes a user about 30 min. to complete.
I have a basic CRUD form that uses PageMethods to update the user details,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.