Teddy Codes
Teddy Codes

Reputation: 489

Value not being inserted into MySQL

I am working with some code that involves MySQL. I create the table and everything is fine until there in an error in the xml that I receive. I added this code:

if(isset($items->Products->Product->AttributeSets->children('ns2', true)->ItemAttributes->ListPrice->Amount) !== False) { 
     $amount = $items->Products->Product->AttributeSets->children('ns2', true)->ItemAttributes->ListPrice->Amount;
}else{
     $amount = 'None';
}
$sqlImport = "INSERT INTO " . $fileName . "(id, asin, amount, salesRank)
VALUES($id, '$asin', $amount, $salesRank)";

When I run this code it give me this error

Unknown column 'None' in 'field list'

I am not sure what the problem is and if anyone could help me I would greatly appreciate it. Thanks in advance!

Upvotes: 0

Views: 39

Answers (2)

Gouda Elalfy
Gouda Elalfy

Reputation: 7023

you forget to put $amount and $salesRank in 2 single quotas and you should to know varchar value should be in 2 ' so your query should be:

$sqlImport = "INSERT INTO " . $fileName . "(id, asin, amount, salesRank)
VALUES('$id', '$asin', '$amount', '$salesRank')";

Upvotes: 1

Alex Moura
Alex Moura

Reputation: 21

change your sql to the below

$sqlImport = "INSERT INTO $fileName (id, asin, amount, salesRank) VALUES ($id, $asin, $amount, $salesRank)";

Upvotes: 0

Related Questions