我有表单通过 jquery 将数据从表单发送到另一个页面,如下所示:-
<?
$counter=0;
$sqlmasmohType = mysql_query("select * from masmoh");
while ($rowmasmohType = mysql_fetch_array($sqlmasmohType))
{
$counter++;
if($counter % 4 == 0){
$class= "no-margin-left";
}else $class="";
?>
<div class="news-element <?= $class ?>"><input type="checkbox" id="masmoh" name="masmoh[]" value="<?=$rowmasmohType['id'] ?>" /> <?=$rowmasmohType['name'] ?></div>
<? } ?>
<div class="clear"></div>
<input type="hidden" name="ft_user_id" id="ft_user_id" value="<?=$iduser?>" class="input-text">
<input type="button" id="save_masmoh_user" name="save_masmoh_user" value="Save" class="custom-btn-train-parentt">
此表单将 2 参数发送到 saveMasmohToUser 页面,此参数之一是数组,我需要将此数组保存到数据库,如 (1,5,p,55)
我会试试这个:-
public function saveMasmohToUser(){
$ft_user_id = $_POST['ft_user_id'];
$save_masmoh = $_POST['save_masmoh'];
$unserializedData = array();
parse_str($save_masmoh,$unserializedData);
if($save_masmoh != ''){
foreach($unserializedData as $unserializedData){
if ($unserializedData != ""){
$check = mysql_query("select count(*) as rowuser from masmoh_for_user where m_user_id = '".$ft_user_id."'");
$rowUser = mysql_fetch_array($check);
if ($rowUser['rowuser'] == 0)
{
$query = mysql_query("insert into masmoh_for_user (m_user_id,m_masmoh) values ('$ft_user_id','".implode($unserializedData, ',')."')");
}
else
{
$query = mysql_query("update masmoh_for_user set m_masmoh = '".implode($unserializedData, ',')."' where m_user_id = '".$ft_user_id."'");
}
$newData = array();
$newData['msg'] = "save";
$data = json_encode($newData);
echo $data ;
}
}
}
}
但我会看到这个错误:-
消息:implode() [function.implode]:传递的参数无效
但是当打印数组时$unserializedData
:-
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)
我该如何解决这个错误。