未定义的变量错误

时间:2012-05-30 01:25:32

标签: php mysql

我正在尝试将amazon api集成到我的网站中,到目前为止,我已设法将其导航到正确的xml部分并将其存储为变量但是我现在正尝试将此varibable插入到我的mysql数据库中,它是给我这个错误

注意:未定义的变量:sql_select in 致命错误:在非对象上调用成员函数query()

我做错了什么?

整个代码

define('INCLUDED', 1);
error_reporting(E_ALL); 
ini_set("display_errors", 1); 
$AWS_ACCESS_KEY_ID = "HIDDENFORPRIVACY";
$AWS_SECRET_ACCESS_KEY = "HIDDENFORPRIVACY";

$base_url = "http://free.apisigning.com/onca/xml?";
$url_params = array('Operation'=>"ItemLookup",'Service'=>"AWSECommerceService",
 'AWSAccessKeyId'=>$AWS_ACCESS_KEY_ID,'AssociateTag'=>"HIDDENFORPRIVACY",
 'Version'=>"2011-08-01",'Availability'=>"Available",'ItemId'=>"0273702440",
 'ItemPage'=>"1",'ResponseGroup'=>"EditorialReview", 'Title'=>"Accounting and Finance for Non-Specialists 5th Edition");

// Add the Timestamp
$url_params['Timestamp'] = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());

// Sort the URL parameters
$url_parts = array();
foreach(array_keys($url_params) as $key)
    $url_parts[] = $key."=".$url_params[$key];
sort($url_parts);

// Construct the string to sign
//$string_to_sign = "GET\nhttp://free.apisigning.com/".implode("&",$url_parts);
//$string_to_sign = str_replace('+','%20',$string_to_sign);
//$string_to_sign = str_replace(':','%3A',$string_to_sign);
//$string_to_sign = str_replace(';',urlencode(';'),$string_to_sign);

// Sign the request
//$signature = hash_hmac("sha256",$string_to_sign,$AWS_SECRET_ACCESS_KEY,TRUE);

// Base64 encode the signature and make it URL safe
//$signature = base64_encode($signature);
//$signature = str_replace('+','%2B',$signature);
//$signature = str_replace('=','%3D',$signature);
//$signature = str_replace(';',urlencode(';'),$string_to_sign);
$url_string = implode("&",$url_parts);
$url = $base_url.$url_string;
//print $url;


$ch = curl_init();                   //this part we set up curl 
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$xml_response = curl_exec($ch);
curl_close($ch);
header('Content-type: application/xml');  //specify as xml to not display as one long string
echo $xml_response; 

$xml = new SimpleXMLElement($xml_response);  //time to echo back the correct piece of data

$editorialReview = $xml->Items->Item->EditorialReviews->EditorialReview->Content;

$variable = '<p>Editorial review: '.html_entity_decode($editorialReview).'</p>'."\n";
echo $variable;

$sql_select = mysql_query("INSERT INTO " . DB_PREFIX . "auctions
            (amazon_description) VALUES
            ('" . $variable . "')");
            echo ($sql_select);

这不会发送错误,但是mysql数据库显示没有变化

1 个答案:

答案 0 :(得分:1)

错误“未定义变量”表示您尚未初始化对象。

从你打印的代码中看来,$ sql_select 应该是一个包含select语句的字符串。

所以你需要做一些事情:

$variable = '<p>Editorial review: '.html_entity_decode($editorialReview).'</p>'."\n";
echo $variable;

$sql_select .= "INSERT INTO " . DB_PREFIX . "auctions
            (amazon_description) VALUES
            ('" . $variable . "')";

$DB_object->query($sql_select);

请发布整个代码,以便准确找到解决方案。