Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
易趣API php错误未定义索引_Php_Indexing_Undefined - Fatal编程技术网

易趣API php错误未定义索引

易趣API php错误未定义索引,php,indexing,undefined,Php,Indexing,Undefined,我正在为一个大学项目使用ebay API实现一个简单的搜索引擎来搜索易趣物品。 我有一个简单的index.php文件,其中包含一个搜索框: <form action="MySample1.php" method="POST"> <input type="text" name="query" size="90" maxlength="255" /> <input type="submit" value="Cerca" /> </FORM&

我正在为一个大学项目使用ebay API实现一个简单的搜索引擎来搜索易趣物品。 我有一个简单的index.php文件,其中包含一个搜索框:

<form action="MySample1.php" method="POST">
    <input type="text" name="query" size="90" maxlength="255" />
    <input type="submit" value="Cerca" /> 
</FORM>

以及用于显示结果的sample.php文件。sample.php文件实现一个函数findItemsByWordsResults,如下所示:

<?php
session_start();
error_reporting(E_ALL);  // Turn on all errors, warnings and notices for easier debugging

// API request variables
$endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1';  // URL to call
$s_endpoint = "http://open.api.ebay.com/shopping?";  // Shopping URL to call
$m_endpoint = 'http://svcs.ebay.com/MerchandisingService?';  // Merchandising URL to call
$version = '1.0.0';  // API version supported
$appid = 'ed-7877-4e90-a4b4-bc6d897f71c3';  // Generated via My Account to ebay developer
$globalid = 'EBAY-US';  // Global ID of the eBay site you want to search (e.g., EBAY-DE)
$responseEncoding = 'XML';  // Type of response we want back
$cellColor = "bgcolor=\"#dfefff\"";  // Light blue background used for selected items
$_SESSION['query'] = $_POST['query'];

function findItemsByKeywordsResults($selectedItemID = '', $cellColor = '') {
    $query= $_SESSION['query'];
    $safequery = urlencode( $query);  // Make the query URL-friendly
    global $endpoint;
    global $appid;
    global $responseEncoding;
    global $version;
    global $globalid;
    global $sort;

    $results = "<FORM ACTION=\"" . $_SERVER['PHP_SELF'] . "\" METHOD=\"POST\"> \n";
    $results .= "<FIELDSET>\n<LEGEND>Sort by: </LEGEND>\n";
    $results .= "<SELECT NAME=\"Order\" onchange=\"this.form.submit();\"> \n";
    $results .= "<OPTION VALUE=\"BestMatch\" SELECTED=\"selected\"> Best Match </OPTION> \n";
    $results .= "<OPTION VALUE=\"BidCountFewest\" > Bid Count Ascending </OPTION>  \n";
    $results .= "<OPTION VALUE=\"BidCountMost\"> Bid Count Descending </OPTION>  \n";
    $results .= "<OPTION VALUE=\"PricePlusShippingLowest\" > Price + Shipping Ascending </OPTION>  \n";
    $results .= "<OPTION VALUE=\"PricePlusShippingHighest\"> Price + Shipping Descending </OPTION>  \n";
    $results .= "</SELECT> \n </FIELDSET> \n";
    $results .= "</FORM> \n";  

    // Construct the findItemsByKeywords HTTP GET call
    $apicall = "$endpoint?";
    $apicall .= "OPERATION-NAME=findItemsByKeywords";
    $apicall .= "&SERVICE-VERSION=$version";
    $apicall .= "&SECURITY-APPNAME=$appid";
    $apicall .= "&GLOBAL-ID=$globalid";
    $apicall .= "&sortOrder=$sort";
    $apicall .= "&keywords=$safequery";
    $apicall .= "&paginationInput.entriesPerPage=10";

    // Load the call and capture the document returned by eBay API
    $resp = simplexml_load_file($apicall);

    // Check to see if the request was successful, else print an error
    if ($resp->ack == "Success") {
        $results .= '';
        // If the response was loaded, parse it and build links

        $results .= "<h2>These are the results for  <i>". $_SESSION['Query'] ."</i> </h2>\n";
        $results .= "<!-- start table in findItemsByKeywordsResults --> \n";
        $results .= "<table width=\"60%\" cellpadding=\"5\" border=\"1\">";

        //for each item node build a table cell and append it to $results
        foreach($resp->searchResult->item as $item){
            // Set the cell color blue for the selected most watched item
            if ($selectedItemID == $item->itemId) {
                $thisCellColor = $cellColor;
            } else {
                $thisCellColor = '';
            }

            // Determine which price to display
            if ($item->sellingStatus->currentPrice) {
                $price = $item->sellingStatus->currentPrice;
            } else {
                $price = $item->listingInfo->buyItNowPrice;
            }

            // For each item, create a cell with imageURL, viewItemURL, watchCount, currentPrice
            $results .= "<tr> \n<td $thisCellColor valign=\"top\"> \n";
            $results .= "<img src=\"$item->galleryURL\"></td> \n";
            $results .= "<td $thisCellColor valign=\"top\"> <p><a href=\"" . $item->viewItemURL . "\">" . $item->title . "</a></p>\n";
            $results .= 'Shipped to: <b>' . $item->shippingInfo->shipToLocations . "</b><br> \n";
            $results .= 'Current price: <b>$' . $price . "</b><br><br> \n";
            $results .= "<FORM ACTION=\"" . $_SERVER['PHP_SELF'] . "\" METHOD=\"POST\"> \n";
            $results .= "<INPUT TYPE=\"hidden\" NAME=\"Selection\" VALUE=\"$item->itemId\"> \n";
            $results .= "<INPUT TYPE=\"submit\" NAME=\"$item->itemId\" ";
            $results .= "VALUE=\"Get Details and Similar Items\"> \n";
            $results .= "</FORM> \n";
            $results .= "</td> </tr> \n\n";
        }
        $results .= "</tr></table> \n<!-- finish table --> \n";
    }
    // If the response does not indicate 'Success,' print an error
    else {
        $results  = "<h3>Oops! The request was not successful. Make sure you are using a valid ";
        $results .= "AppID for the Production environment.</h3>";   
    }
    return $results;
}//end of the function

而不是下面的代码:

$_SESSION['query'] = $_POST['query'];
使用以下代码:

$_SESSION['query'] = isset($_POST['query']) ? $_POST['query'] : (isset($_SESSION['query']) ?$_SESSION['query'] : '' );

$\u POST['query']未设置,您提交表单时未填写
query
field第23行
C:\xampp\htdocs\GettingStarted\Sample.php中的第23行
?$\u会话['query']=$\u POST['query'];是行。@user2092317将其作为答案发布。@user2092317:如果未填写,
$\u Post['query']
为空(
“”
)且未取消定义错误:哎呀!请求未成功。请确保为生产环境使用了有效的AppID。@这是另一个问题,您需要为
$AppID
变量使用正确的值。是的,但这是我在第行代码中实现的错误消息66@albinf第66行是哪一行?否则{$results=“哎呀!请求未成功。请确保您使用的是有效的”;$results.=“生产环境的AppID。”;}我确信我在index.php中填写了查询检查您的表单操作是
MySample1.php
,并且您正在显示
sample.php
,请检查我正在运行MySample1.php,但我编写sample.php只是为了让它看起来更好。lol
$_POST['query']; is not set, you are submitting the form without filling query