您好先生我通过url传递arraylist从android传递到php所有数组列表插入到单个coloumn中的一行。我想将一列(menuname)插入多行
EG:
i pass array list[x,y,z.........] android to php
mysql
menuname
x
y
z(i want like this)
i try this code
<?php
$arr[]=$_POST['menuname'];
mysql_connect("localhost","root","mobixmysql");
mysql_select_db("test");
foreach($arr as $value){
$value;
mysql_query("INSERT INTO test (menuname) VALUES ('" .
mysql_real_escape_string($value) . "')")or
die('unable'.mysql_error());
echo "inserted";
}
?>
我尝试上面的代码,它将数据库插入到一行的menuname列中。我想在一列中添加多行
答案 0 :(得分:1)
我认为$_POST['menuname']
不是数组;
<?php
$arr=explode(',',preg_replace('/^.*\[(.*)\].*$/','$1',$_POST['menuname']));
mysql_connect("localhost","root","mobixmysql");
mysql_select_db("test");
foreach($arr as $value){
mysql_query("INSERT INTO test (menuname) VALUES ('" .
mysql_real_escape_string($value) . "')")or
die('unable'.mysql_error());
echo "inserted";
}
?>