从Array中的Selected Values插入MySQL Table

时间:2015-05-15 17:25:06

标签: php mysql arrays

我很难搞清楚确切的代码。我可能有错误的语法或做同样的非常有限的知识。任何帮助表示赞赏。

$Game = array('ASIN' => $field->ASIN,
                        'title' => $field->title,
                        'price' => $field->price,
                        'quantity' => $field->quantity);
 $sql = "INSERT INTO GameTable (`ASIN`, `Title`, `Price`, `Quantity`) "
                        . "VALUES ($Game['ASIN'],  $GAME['title'], "
                                . "$GAME['price'], $GAME['quantity'])"

1 个答案:

答案 0 :(得分:-1)

此代码:

$sql = "INSERT INTO GameTable (`ASIN`, `Title`, `Price`, `Quantity`) "
                        . "VALUES ($Game['ASIN'],  $GAME['title'], "
                                . "$GAME['price'], $GAME['quantity'])"

应该成为

$asin = $game['asin'];
$title = $game['title'];
$price = $game['price'];
$quantity = $game['quantity'];
$sql = "INSERT INTO GameTable (`ASIN`, `Title`, `Price`, `Quantity`) 
        VALUES ('$asin',  '$title', '$price', '$quantity')";

注意使用大写字母,注意php变量区分大小写。