Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript发送变量但插入数组php无法正常工作_Javascript_Php_Jquery_Mysql - Fatal编程技术网

javascript发送变量但插入数组php无法正常工作

javascript发送变量但插入数组php无法正常工作,javascript,php,jquery,mysql,Javascript,Php,Jquery,Mysql,我有一个与此代码的问题,在插入只插入在每个插入的第一个项目的价格,在例子中,我有三个不同的项目的价格,谢谢你的帮助抱歉糟糕的英语 表格中的html部分: <table> <tr id="shop1"> <td>1</td> <!-- item_id --> <td><input type="text" value="33" name="price"></td> <!-- item_price -

我有一个与此代码的问题,在插入只插入在每个插入的第一个项目的价格,在例子中,我有三个不同的项目的价格,谢谢你的帮助抱歉糟糕的英语

表格中的html部分:

<table>
<tr id="shop1">
<td>1</td> <!-- item_id -->
<td><input type="text" value="33" name="price"></td> <!-- item_price -->
</tr>
<tr id="shop2">
<td>2</td> <!-- item_id -->
<td><input type="text" value="11" name="price"></td> <!-- item_price -->
</tr>
<tr id="shop3">
<td>3</td> <!-- item_id -->
<td><input type="text" value="65" name="price"></td> <!-- item_price -->
</tr>
</table>
<button id="checkoutinventory" class="btn-danger"></button>
process.php部分:

if ($_GET['action'] == "checkoutinventory")
    {
        if (!@$character)
            exit("REFRESH");

        if (!$VALIDATE->blank(@$_GET['items']))
            exit();

        $items = explode(",", rtrim($_GET['items'],",")); //Here obtain item_id in this format: id_1,id_2,id_3,etc
        $price = $_GET['price']; //Here obtain item_price in this format: price1,price2,price3,etc

        $isonline = $SERVER->select($query['characterIsonline'],array($COOKIE->get("character")));

        if(!$isonline)
        {
            $itemData = $SERVER->select("SELECT * FROM `items` WHERE `object_id` IN (".implode(",",$items).");",array()); //Here obtain perfectly information for insert later in foreach
        } else {
            exit("RESPONSE^ERROR^Your character <b>".$character['char_name']."</b> is online disconnect please and try again..");
        }
        if($itemData) {
            foreach($itemData as $itemlist)
                {
                $selling = $SERVER->insert("INSERT INTO `shop_items` (`itemId`,`itemAmount`,`itemPrice`,`itemEnchant`,`vendedor`,`object_id`) VALUES (?,?,?,?,?,?);",array($itemlist['item_id'],$itemlist['count'],$_GET['price'],$itemlist['enchant_level'],$character['char_name'],$itemlist['object_id']));
            }
        }

        if (count($items) != count($itemData))
            exit("RESPONSE^ERROR^One of the items is no longer available for sale.");

        if($selling) {
            exit("RESPONSE^SUCCESS^Congrats <b>".$character['char_name']."</b>, you sell ".count($items)." item(s)!");
            }

        exit("RESPONSE^ERROR^Unexpected error occured.");
    }
if($\u GET['action']==“checkoutinventory”)
{
如果(!@$字符)
退出(“刷新”);
如果(!$VALIDATE->blank(@$\u GET['items']))
退出();
$items=explode(“,”,rtrim($\u-GET['items'],“,”);//此处获取以下格式的item\u id:id\u 1、id\u 2、id\u 3等
$price=$\u GET['price'];//此处获取以下格式的商品价格:price1、price2、price3等
$isonline=$SERVER->select($query['characterizationOnline'],数组($COOKIE->get(“character”));
如果(!$isonline)
{
$itemData=$SERVER->select(“select*FROM`items`WHERE`object_id`IN(“.infrade(“,”,$items)”);“,array());//在这里可以获得完整的信息,以便以后在foreach中插入
}否则{
退出(“响应^ERROR^您的字符“$character['char\u name']”处于联机状态请断开连接并重试..”);
}
如果($itemData){
foreach($itemData作为$itemlist)
{
$selling=$SERVER->insert(“插入到'shop_items`('itemId`、'itemAmount`、'itemPrice`、'itemEnchant`、'vendedor`、'object_id`、'object_id`)值(?,,,?,?,?,?,?,?,?);”数组($itemlist itemlist['itemlist['count',$itemlist['price'],$itemlist['ench_level'],$character['character['char name',$itemlist['object id']))));
}
}
如果(计数($items)!=计数($itemData))
退出(“响应^ERROR^其中一个项目不再出售。”);
如果(出售){
退出(“响应^SUCCESS^恭喜”。$character['char_name']),您卖出了。计数($items)。“item(s)!”;
}
退出(“响应^ERROR^发生意外错误”);
}

假设您希望按位置将价格与商品匹配(即价格数组中的第一个值属于商品数组中的第一个值)


更新解释抱歉:嗨!,我对这段代码有一个问题,在INSERT中只插入每个INSERT中的第一个项目价格,在示例中我有三个不同的项目价格,谢谢你的帮助,抱歉糟糕english@JulianAlbarracinCruz我不理解你的问题,因为我认为这就是你想要的修复工作,但在表中插入重复记录,看到我的回答了吗?我刚刚看到你的评论更新了,这是解决方案!非常感谢:D数组_shift
if ($_GET['action'] == "checkoutinventory")
    {
        if (!@$character)
            exit("REFRESH");

        if (!$VALIDATE->blank(@$_GET['items']))
            exit();

        $items = explode(",", rtrim($_GET['items'],",")); //Here obtain item_id in this format: id_1,id_2,id_3,etc
        $price = $_GET['price']; //Here obtain item_price in this format: price1,price2,price3,etc

        $isonline = $SERVER->select($query['characterIsonline'],array($COOKIE->get("character")));

        if(!$isonline)
        {
            $itemData = $SERVER->select("SELECT * FROM `items` WHERE `object_id` IN (".implode(",",$items).");",array()); //Here obtain perfectly information for insert later in foreach
        } else {
            exit("RESPONSE^ERROR^Your character <b>".$character['char_name']."</b> is online disconnect please and try again..");
        }
        if($itemData) {
            foreach($itemData as $itemlist)
                {
                $selling = $SERVER->insert("INSERT INTO `shop_items` (`itemId`,`itemAmount`,`itemPrice`,`itemEnchant`,`vendedor`,`object_id`) VALUES (?,?,?,?,?,?);",array($itemlist['item_id'],$itemlist['count'],$_GET['price'],$itemlist['enchant_level'],$character['char_name'],$itemlist['object_id']));
            }
        }

        if (count($items) != count($itemData))
            exit("RESPONSE^ERROR^One of the items is no longer available for sale.");

        if($selling) {
            exit("RESPONSE^SUCCESS^Congrats <b>".$character['char_name']."</b>, you sell ".count($items)." item(s)!");
            }

        exit("RESPONSE^ERROR^Unexpected error occured.");
    }
if($itemData) {
    $prices = explode(',',$price); //create an array of prices

    foreach($itemData as $itemlist) {

        $single_price = array_shift($prices); //remove the 1st price from array

        $selling = $SERVER->insert("INSERT INTO `shop_items` 
            (`itemId`,`itemAmount`,`itemPrice`,`itemEnchant`,`vendedor`,`object_id`) 
            VALUES (?,?,?,?,?,?);",
            array($itemlist['item_id'],$itemlist['count'],$single_price,$itemlist['enchant_level'],$character['char_name'],$itemlist['object_id']));
    }
}