For循环只将数据的第一个字符插入db

时间:2016-06-25 15:52:06

标签: php mysql

我有这个令人沮丧的问题,我使用for循环将数据插入数据库,数据插入到数据库中,但它只插入第一个字符,例如代替插入单词示例,它将只插入字母e。 见下面的丝网印刷:

enter image description here 第一行是示例行

这是我第一次使用for循环,所以我想知道我的错误是否在我的代码中遗漏了,这导致了这个问题。

代码

$_query = array();

for ($x = 0; $x < count($OI); $x++) {

$_query = "INSERT INTO ord_dets(Order_ID,custmer_ip,Resturant_ID,Resturant_name,City_name,
Product_Id,Product_Name,Product_Price,item_sub) 
VALUES ('" . $OI[$x] . "', '" . $ip[$x] . "','" . $_SESSION['rest_id'][$x] . "','" . $rest_name[$x] . "',
        '" . $City_name[$x] . "','" . $Product_Id[$x] . "','" . $product_name[$x] . "','" . $prod_price[$x] . "','" . $item_sub[$x] . "')";

            }
            $query_run = $dbc->prepare($_query);
            echo $_query;

            if (!$query_run->execute()) {
                $insertError = "There was an error inserting data: " . $query_run->error;
                print "affected rows:" . $query_run->affected_rows; //how many records affected?         
            }
        }
    }

0 个答案:

没有答案