0

I am trying to get information into my database and am running into a problem that I am sure I am just making a simple mistake. To update the table I am using:

    $conn->query("update webPrice set price= " . $amazonResult['price'] . " where asin = '" . $amazonResult['asin'] . "'");

$conn is my connection. The price is consistently entered as 0. I know there is information there since when I do print_r($amazonResult) I see everything that I want to insert into the DB. Code to get amazon info is:

    foreach($parsed_xml->GetMyPriceForASINResult as $item ) {
 $asin2 =$item->attributes()->ASIN;
$current = $item->Product;

 $status = $item->attributes()->status;

      if (stristr($status, "Success") == true)
{
        $amazonResult = array(
                        'asin' => $asin2,
            'price' => $current->Offers->Offer->BuyingPrice->ListingPrice,//AttributeSets->children('ns2', true)->
                            );

I think the issue is with my update statement, but I an not sure what it is. The asin info is entered correctly. the fields are price = double and asin = varchar.

EDIT: here is the result of print_r($amazonResult);

Array ( [asin] => SimpleXMLElement Object ( [0] => 0176055452 ) [price] => SimpleXMLElement Object ( [CurrencyCode] => USD [Amount] => 10.11 ) )

2 Answers 2

1

Try, adding quotes ' around $amazonResult['price']

$conn->query("update webPrice set price= '" . $amazonResult['price'] . "' where asin = '" . $amazonResult['asin'] . "'");

Edit: As per your edit, as the values are in objects,

$conn->query("update webPrice set price= '" . $amazonResult['price']->Amount . "' where asin = '" . $amazonResult['asin']->0 . "'");
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks I just tried your suggestion, and get the same result.
Edited my answer, as per the edit in the question. Take a look.
I knew it would be something simple. Thanks, that worked perfectly.
1

You have to put the names of the table and the fields in between two of this sign: ` And You have to use the ' sign for values. (like coder1984 said)

$conn->query("update `webPrice` set `price` = '" . $amazonResult['price'] . "' where `asin` = '" . $amazonResult['asin'] . "'");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.