MySQL插入空行

I have an array of object that I want to insert into database.
So I'm looping all objects with for loop.

I'm sending $offer and $gameid with ajax
$offer is array with 10 items and $gameid is just integer

All variables have data because it echo them.

I'm working on xampp with localhost

include "../../inc/connect.php";

$offer = @$_POST['offer'];
$gameid = @$_POST['gameid'];

$query = $db->prepare("INSERT INTO items VALUES (id, gameid, assetid, name, icon, price, owner)");

for($i = 0; $i < count($offer) - 1; $i++) {
    $assetid = $offer[$i]['assetid'];
    $name = $offer[$i]['name'];
    $icon = $offer[$i]['icon'];
    $price = $offer[$i]['price'];

    $query_array = array('id' => '', 'gameid' => $gameid, 'assetid' => $assetid, 'name' => $name, 'icon' => $icon, 'price' => $price, 'owner' => $steamid);

    $query->execute($query_array);

echo "
<div class='item'>
    <div class='left'>
        <img src='$avatar' />
        <div class='names'>
            <p>$username</p>
            <p>$name</p>
        </div>
    </div>
    <div class='right'>
        <div class='price'>
            $" . $price . "
        </div>
        <div class='item-icon'>
            <img src='http://cdn.steamcommunity.com/economy/image/$icon' />
        </div>
    </div>
</div>  
";
}

Connect

$user = "root";
$pass = "";

$db = new PDO('mysql:host=localhost;dbname=website', $user, $pass);

Table

enter image description here

What I get when $query->execute($query_array)

enter image description here

No errors in mysql_error.log or in ajax data

查看全部
weixin_33738982
?Briella
2017/01/04 14:32
  • php
  • mysql
  • ajax
  • sql
  • 点赞
  • 收藏
  • 回答
    私信

2个回复