我需要有关将数组插入 mysql 表的帮助。
当我将商品添加到购物车时,我有一个数组
$_session['cart_array'] = array("item_id" => $pid, "quantity"=>1)
现在,如果我执行 print_r($_session['cart_array'])
数组时购物车中有一件商品
Array( [0] => Array ( [item_id] => 1 [quantity] => 1 ) )
现在我需要将此数组数据插入到名为purchased_products 的表中,该表包含列
id, product_name, product_quantity
最佳答案
$item_id = $_session['cart_array'] [item_id];
$quantity = $_session['cart_array'] [quantity];
然后尝试将该变量插入数据库:
$insert = mysql_query("INSERT INTO table_name VALUES ('NULL', '".$item_id."', '".$quantity."')");
如果您的 id 自动递增,请使用 NULL。
希望能帮到你..
关于PHP MySql 数组插入表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9816231/