Avatar of ES-Components
ES-Components
Flag for United States of America asked on

How To Create A http Get Request URL?

I am using a MYSQL Server and using php to run an Inventory Search page on my website.
A supplier of ours is requesting us to provide them with a HTTP Get Request URL that implements a part search on our website. Currently I use a form on our website that searches a database table for the item and displays the results on an inventory_srch_results page.
Is there a way of doing what our supplier is asking?

Our website is: http://www.escomponents.com (The home page has a search form)
The results page is: inventory_srch_resultsRR.php

Any help would be greatly appreciated.

Thank you...
Rick
Programming

Avatar of undefined
Last Comment
ES-Components

8/22/2022 - Mon
gr8gonzo

Data can be transmitted to a web server either via POST or a GET. When you POST data to a web server from a search form, for example, the data doesn't show up in the address bar.

Your search results still looks like this:
http://www.escomponents.com/inventory_srch_resultsRR.php

A GET request is when you are just asking the web server for a specific page, but you're not POSTing data. So when you go to your home page in your browser:

http://www.escomponents.com

...that is a GET request.

You can also pass data in a GET request, in a part of the URL known as the "query string." If you see a question mark in a URL, you're seeing the part that splits the URL from the data.

So if I went here:

http://www.escomponents.com?hello=world&name=Rick

...then I am still getting the same page, but PHP has access to GET variables called "hello" and "name". The value for the "hello" GET variable is "world", and the value for "name" is "Rick".

Now, currently your search form sends POST data to the inventory search engine, and your search engine expects POST data. For example, the field that it sends for the search word is called "srchCriteria".

Your supplier seems to be asking you for a version of your inventory search engine that will allow them to type in a part number in the URL and search that way, like this:

http://www.escomponents.com/inventory_srch_resultsRR.php?srchCriteria=ADG

However, it seems that your search engine is only looking for POST data and not GET data.

One quick way of resolving this (but not necessarily the best way) is to change any references to $_POST in the search engine results page to $_REQUEST. The $_REQUEST variables look at both POST and GET data and takes whichever one is available.

All that said, I would be cautious about doing this and would suggest hiring a freelance developer (elance.com and sites like it have contractors for hire) to make the change. You could accidentally open up security risks if you are not careful with what you're changing or understand all of the changes.
gr8gonzo

Also, just for additional information...

Usually when third parties want to search your site for information using GET data, they are often building their own tools to programmatically access your data. They probably have their own system and they want that system to automatically do searches as necessary without people actually having to go to your web site.

The concept called "REST" services is usually what they are looking for. REST is basically a fancy acronym for someone giving you their search parameters via GET, and you returning some kind of formatted response. Often times, people don't want a full web page with all the images and all that, but an encoded response that is easy for programming languages to read. A lot of REST services return data in JSON-encoded format. This simply means that instead of sending back a bunch of HTML with all the images, headers, footers, etc... you're sending back a response that looks like:

[{ "ADG123" : { "Supplier" : "Me", "Colors" : ["Green","Blue"] }, "ADG456" : { "Supplier" : "MeToo", "Colors" : ["Red"] }];

It's not very easy to read by humans, but it's really easy for programming languages to read.

So that might be something you want to ask your supplier ("Do you want the GET version to return JSON-encoded data?") ....if you're going to provide this functionality for them. Not only will it make them happier, but it will reduce the amount of data that you have to send them each time.
ES-Components

ASKER
I did make the change to $_REQUEST on the inventory_srch-resultsRR.php page.
When I enter a search
http://www.escomponents.com/inventory_srch_resultsRR.php?srchCriteria=2n2222a

all I get for results are all of my products. I should only get approx. twenty items.

Is there something else that I need to do?

Thank you again for your quick response and I do understand what you are talking about.

Rick
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
gr8gonzo

It probably means there's some other code that isn't being executed properly. If you want to post the code for the search results page, we might be able to figure out what to change.
ES-Components

ASKER
See code below......

Thank you...Rick

<?php
//WA Database Search Include
require_once("WADbSearch/HelperPHP.php");
?>
<?php
//WA Database Search (Copyright 2005, WebAssist.com)
//Searchpage: index.php;
//Form: escINVsrch;
$WADbSearch1_DefaultWhere = "";
if (!session_id()) session_start();
if ((isset($_REQUEST["WADbSearch1"])) && ($_REQUEST["WADbSearch1"] != "")) {
  $WADbSearch1 = new FilterDef;
  $WADbSearch1->initializeQueryBuilder("MYSQL","1");
  //keyword array declarations
  $KeyArr1 = array("ProdMfg");
  $KeyArr2 = array("ProdSrchDesc");

  //comparison list additions
  $WADbSearch1->keywordComparison($KeyArr1,"".((isset($_REQUEST["compSLCT"]))?$_REQUEST["compSLCT"]:"")  ." (,%20:%20:%22:%22)","AND","Includes",",%20","%20","%22","%22",0);
  $WADbSearch1->keywordComparison($KeyArr2,"".((isset($_REQUEST["srchCriteria"]))?$_REQUEST["srchCriteria"]:"")  ." (,%20:%20:%22:%22)","AND","Includes",",%20","%20","%22","%22",0);

  //save the query in a session variable
  if (1 == 1) {
    $_SESSION["WADbSearch1_inventory_srch_results"]=$WADbSearch1->whereClause;
  }
}
else     {
  $WADbSearch1 = new FilterDef;
  $WADbSearch1->initializeQueryBuilder("MYSQL","1");
  //get the filter definition from a session variable
  if (1 == 1)     {
    if (isset($_SESSION["WADbSearch1_inventory_srch_results"]) && $_SESSION["WADbSearch1_inventory_srch_results"] != "")     {
      $WADbSearch1->whereClause = $_SESSION["WADbSearch1_inventory_srch_results"];
    }
    else     {
      $WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
    }
  }
  else     {
    $WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
  }
}
$WADbSearch1->whereClause = str_replace("\\''", "''", $WADbSearch1->whereClause);
$WADbSearch1whereClause = $WADbSearch1->whereClause;
?>
<?php
//WA eCart Include
require_once("WA_eCart/escQR_PHP.php");
?>
<?php require_once('Connections/NSESC.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$escQR->GetContent();
?>
<?php
$WADbSearch1whereClause_esc = "AND 0=0";
if (isset($WADbSearch1whereClause)) {
  $WADbSearch1whereClause_esc = $WADbSearch1whereClause;
}
$WADbSearch1whereClause_esc = "AND 0=0";
if (isset($WADbSearch1whereClause)) {
  $WADbSearch1whereClause_esc = (get_magic_quotes_gpc()) ? $WADbSearch1whereClause : addslashes($WADbSearch1whereClause);
}
mysql_select_db($database_NSESC, $NSESC);
$query_esc = sprintf("SELECT * FROM ESCInv WHERE 0=0 %s ORDER BY SortQTY DESC ", $WADbSearch1whereClause_esc);
$esc = mysql_query($query_esc, $NSESC) or die(mysql_error());
$row_esc = mysql_fetch_assoc($esc);
$totalRows_esc = mysql_num_rows($esc);
?>
<?php
// WA eCart Redirect
if ($escQR->redirStr != "")     {
  header("Location: ".$escQR->redirStr);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>ES Components Specialty distributor of Discrete and Passive Components</title>
<meta name="description" content="Leading Discrete and Passive Component Specialist. Bare Die, Wafer and SMT Solutions.">
<meta name="keywords" content="Bare Die, Wafer, Diodes, Transistors, MOSFETS, JFETS, Optoelectronics, Resistors, Capacitors, Inductors">

<style type="text/css">
<style type="text/css">
#vertmenu {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
width: 140px;
padding: 0px;
margin: 0px;
}

#vertmenu h1 {
display: block;

font-size: 100%;
padding: 3px 0 5px 3px;
border-left: 1px solid #b99a62;
color: #FFFFFF;
margin: 0px;
width:160px;
}

#vertmenu ul {
list-style: none;
margin: 0px;
padding: 0px;
border: none;
}
#vertmenu ul li {
margin: 0px;
padding: 0px;
}
#vertmenu ul li a {
font-size: 11px;
display: block;
border-bottom: 1px dashed #B99A62;
padding: 5px 0px 2px 4px;
text-decoration: none;
color: #B99A62;
width:140px;
}

#vertmenu ul li a:hover, #vertmenu ul li a:focus {
color: #000000;
background-color: #B99A62;
}
<!--
1
 { border-bottom-style: dashed ;
border-bottom-color: yellow;
border-bottom-width: 5px; }

ul#menu {
   
    border: 0px solid #DDD;
    height: 0px;
    list-style-type: none;
    margin-bottom: 0px;
    padding: 0px;
}
ul#menu li {
    border-right: 1px solid #DDD;
    float: left;
}
ul#menu li a {
    color: #FFF;
    display: block;
    font: 8pt MS Sans Serif;
    height: 15px;
    padding: 0px 6px 0px;
    text-decoration: none;
}

.Backg, .Backg TD, .backg TH
{
background-image:url(images/gradient54754637.png);
background-repeat: repeat-x; background-color:#746d3a;
}
body {
      background-image: url();
      margin-top: 0px;
}
.style184 {
      font-size: 11px;
      font-weight:normal;
      color: #ffffff;
      font-family: Arial, Helvetica, sans-serif;
}
a:link {
      color: #000000;
      text-decoration: none;
}
a:visited {
      text-decoration: none;
      color: #000000;
}
a:hover {
      text-decoration: underline;
      color: #333333;
}
a:active {
      text-decoration: none;
      color: #000000;
}
.style239 {
      font-family: Arial, Helvetica, sans-serif;
      font-size: 11px;
      color: #000000; font-weight: bold;
}
.style248 {color: #ffffff}
.style187 {font-size: 14px}
.style186 {font-size: 12px; color: #cccccc; }
.style221 {font-size: 14px; color: #cccccc; }
.style236 {font-size: 36px; color: #b99a62; }
.style42 {      font-size: 30px;
      font-family: Arial, Helvetica, sans-serif;
      color: #ffffff;
}
.style62 {font-size: 25px}
.style73 {font-size: 30px}
.style78 {font-size: 20px}
.solidblockmenu{
margin: 0;
padding: 0;
float: left;
font:  12px Arial;
width: 100%;
overflow: hidden;

border: 1px solid #625e00;
border-width: 1px 0;
background: #534f20 url(images/blockdefault.gif) center center repeat-x;
}

.solidblockmenu li{
display: inline;
}

.solidblockmenu li a{
float: left;
color: white;
padding: 9px 11px;
text-decoration: none;
border-right: 1px solid white;
}

.solidblockmenu li a:visited{
color: white;
}

.solidblockmenu li a:hover, .solidblockmenu li .current{
color: white;
background: transparent url(images/blockactive.gif) center center repeat-x;
}
.style325 {
      color: #f9f7b4;
      font-size: 24px;
}
.style432 {color: #000000}
.style433 {font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #000000; }
.style21 {      font-family: "MS Sans Serif";
      font-size: 10px;
      color: #FFFFFF;
}
.style245 {font-family: Arial, Helvetica, sans-serif}
.style25 {font-family: Arial, Helvetica, sans-serif; font-size: 13px; color: #000000; }
.style253 {color: #cccccc}
.style368 {color: #FFFFFF}
.style426 {color: #f9f7b4;
      font-family: Arial, Helvetica, sans-serif;
      font-size: 16px;
}
.style446 {font-size: 10px; font-family: Arial, Helvetica, sans-serif; }
.style449 {font-family: "Arial Narrow"}
.style458 {font-size: 13px}
.style460 {font-family: Arial, Helvetica, sans-serif; font-size: 13px; }
.style465 {font-size: 24px;
      font-weight: bold;
      font-family: Arial, Helvetica, sans-serif;
}
.style466 {      font-family: Arial, Helvetica, sans-serif;
      font-size: 14px;
      color: #000000;
}
.style85 {color: #000000; font-weight: bold; }
-->
</style>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-8733713-2']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>

<body>
<table width="819" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#2d2b16">
  <tr>
    <td><ul class="solidblockmenu">
        <li><a href="index.php">Home</a></li>
        <li><a href="CompanyInfR.php">About Us</a></li>
        <li><a href="ProductR.php">Product</a></li>
            <li><a href="/pdf/LineCard81911.pdf">Line Card</a></li>
        <li><a href="DMSMSRNew.php">DMSMS</a></li>
        <li><a href="AskTheQuestionR.php">Quote</a></li>
        <li><a href="ServiceR.php">Services</a></li>
        <li><a href="QualityR.php">Quality</a></li>
        <li><a href="ResourceR.php">Resources</a></li>
        <li><a href="AskTheQuestionR.php">Help</a></li>
        <li><a href="ContactR.php">Contact</a></li>
        <li>
          <div align="center"><a href="SiteMaR.php">Site Map</a></div>
        </li>
    </ul></td>
</table>
<table width="100" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><img src="/images/Banner2012.png" alt="Bare Die SMT Distribution At ES Components" width="819" height="150"></td>
  </tr>
</table>
<div align="center"><br>
    <a href="/ContactR.php"><img src="/images/GrnButContactSales.png" width="204" height="50" border="0"></a> <a href="/AskTheQuestionR.php"><img src="/images/GrnButRequestQte.png" width="204" height="50" border="0"></a> <a href="/QualityR.php"><img src="/images/GrnButQuality.png" width="204" height="50" border="0"></a> <a href="/CompanyInfR.php"><img src="/images/GrnButAboutUs.png" width="204" height="50" border="0"></a><br>
    <table width="819" height="317" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="819" height="317" valign="top" class="style21"><div align="center"> <br>
                <table width="819" border="0" align="center" cellpadding="0" cellspacing="0">
                  <tr>
                    <td width="534" height="296" valign="top"><div align="left">
                        <p align="left" class=""><span class=""><span class="style432"><span class="style465"><table width="563" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td colspan="5"><div align="center"><span class="style42"><span class="style62"><span class="style78"><span class="style73"><span class="style184 style191"><span class="style221"><span class="NAVBAR"><span class="style186"><span class="style187"><span class="style236 style325">                <span class="style85">Available Inventory</span></span></span></span></span></span></span></span></span></span></span></div></td>
            </tr>          
            <tr>
              <td colspan="5"><?php if ($totalRows_esc == 0) { // Show if recordset empty ?>
                <table width="568" border="0" align="center" cellpadding="0" cellspacing="0">
                  <tr>
                    <td>&nbsp;</td>
                  </tr>
                </table>
                <?php } // Show if recordset empty ?></td>
            </tr>
            <tr>
              <td colspan="5"><?php if ($totalRows_esc > 0) { // Show if recordset not empty ?>
                <table width="466" border="1" align="center" cellpadding="1" cellspacing="0" bordercolor="#000000" bgcolor="cde0c6">
                  <tr>
                    <td width="268"><div align="center" class="style239">Manufacturer / Part # / Description:</div></td>
                    <td width="60"><div align="center" class="style239">Type:</div></td>
                    <td width="60"><div align="center" class="style239">Available<br>
                        Qty</div></td>
                    <td width="60"><div align="center" class="style239">Add<br>
          to<br>
          RFQ</div></td>
                    </tr>
                  <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    </tr>
                  <?php do { ?>
                  <tr>
                    <td height="78"><table width="240" border="0" align="center" cellpadding="0" cellspacing="0">
                        <tr>
                          <td><div align="center" class="style239 style432"><?php echo $row_esc['ProdMfg']; ?></div></td>
                        </tr>
                        <tr>
                          <td><div align="center" class="style433"><?php echo $row_esc['ProdDesc']; ?></div></td>
                        </tr>
                        <tr>
                          <td><div align="center" class="style433"><?php echo $row_esc['VTFDescription']; ?></div></td>
                                      <tr>
                                       <td><div align="center" class="style433"><?php echo $row_esc['Desc3']; ?></div></td>
                        </tr>
                    </table></td>
                    <td><div align="center" class="style433"><?php echo $row_esc['Type']; ?></div></td>
                    <td><div align="center" class="style433"><?php echo $row_esc['ProdQty']; ?></div></td>
                    <td><div align="center" class="style239"><a href="inventory_detail_addRR.php?ID=<?php echo $row_esc['ProdID']; ?>" class="style248">Add &gt;&gt;</a></div></td>
                    </tr>
                  <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    </tr>
                  <?php } while ($row_esc = mysql_fetch_assoc($esc)); ?>
                </table>
                <?php } // Show if recordset not empty ?></td>
            </tr>
          </table><br>
</span></span></span></p>
                        </div></td>
                    <td width="19" align="center" valign="top"><span class="style460"><span class="style253 style245 style397 style385 style368"><span class="style449 style187 style432"><strong><br>
                                <br>
                                <br>
                      </strong></span></span></span><br>
                      <br>
                    </td>
                    <td width="266" valign="top"><table width="229" height="200" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                          <td width="229" align="center" valign="top" background="images/GrnInv.png"><span class="style368"><span class="style426">Inventory Search</span> <br>
                                <br>
                            </span>
                              <table width="220" border="0" align="center" cellpadding="0" cellspacing="0">
                                <tr>
                                  <td width="220"><form action="inventory_srch_resultsRR.php" method="REQUEST" name="escINVsrch" class="" id="escINVsrch">
                                      <p align="left"><span class="style253"> </span>
                                          <input name="srchCriteria" type="text" class="style460" id="srchCriteria" value="Enter Part#" size="18" maxlength="255" />
                                          <input name="Submit" type="submit" class="SearchButtonGO" value="Go" />
                                          <input type="hidden" name="WADbSearch1" value="Submit" />
                                    </form></td>
                                </tr>
                                <tr>
                                  <td><form action="DMSMSRNew.php" method="REQUEST" name="form3" class="">
                                      <div align="left">
                                        <div align="right"><span class="style466"><span class="style458">DMSMS Components</span>&nbsp; </span><span class="style446">
                                          <input name="submit" type="submit" class="SearchButtonGO" value="Go">
                                        </span></div>
                                      </div>
                                  </form></td>
                                </tr>
                                <tr>
                                  <td><form action="VishayThinFilmR.php" method="REQUEST" name="form3" class="">
                                      <div align="right"><span class="style449"><span class="style245 style432 style458"> <span class="style432">Vishay Thin Film Resistors</span></span><span class="style466">&nbsp;</span></span>
                                          <input name="Submit" type="submit" class="SearchButtonGO" value="Go">
                                      </div>
                                  </form></td>
                                </tr>
                                <tr>
                                  <td><form action="DiodeDieSolutionsR2.php" method="REQUEST" name="form3" class="">
                                      <div align="right"><span class="style245 style458 style432 style86">Diode Die Solutions</span><span class="style25">&nbsp;</span>
                                          <input name="Submit" type="submit" class="SearchButtonGO" value="Go">
                                      </div>
                                  </form></td>
                                </tr>
                              </table>
                              <span class="style368"> </span></td>
                        </tr>
                      </table>
                        <table width="266" height="96" border="0" cellpadding="0" cellspacing="0">
                          <tr>
                            <td width="266" height="96" align="left" valign="top"><span class="style460"><span class="style253 style245 style397 style385 style368"><span class="style432 style458 style86"><strong>Hybrid Designer's Toolbox</strong></span></span></span><br>
                                <table width="257" height="74" border="0" cellpadding="0" cellspacing="0">
                                  <tr>
                                    <td width="105" background="images/redgreenbox102x73.png">&nbsp;</td>
                                    <td width="152" valign="top"><table width="136" border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                          <td width="136" height="22"><span class="style460"><span class="style253 style245 style458"><a href="/ToolboxMap.php">Selector Guides</a></span></span></td>
                                        </tr>
                                        <tr>
                                          <td height="16"><span class="style460"><span class="style253 style245 style458"><a href="/ToolboxMap.php">Cross Reference</a></span></span></td>
                                        </tr>
                                        <tr>
                                          <td height="16"><span class="style460"><span class="style253 style245 style458"><a href="/ToolboxMap.php">Active Components</a></span></span></td>
                                        </tr>
                                        <tr>
                                          <td height="16"><span class="style460"><span class="style253 style245 style458"><a href="/ToolboxMap.php">Passive Components</a></span></span></td>
                                        </tr>
                                    </table></td>
                                  </tr>
                              </table></td>
                          </tr>
                        </table>
                        <div align="right"></div></td>
                  </tr>
                </table>
        </div></td>
      </tr>
    </table>
</div>

</body>
</html>
<?php
mysql_free_result($esc);
?>
ASKER CERTIFIED SOLUTION
gr8gonzo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ES-Components

ASKER
You are the BEST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
It works perfectly each time. All we needed was the additional parameter.

Again, THANK YOU VERY VERY MUCH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Rick
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.