dongtang1997 2011-09-14 11:25
浏览 47

Mysqli问题:类型定义字符串中的元素数与绑定变量数不匹配

Now this sounds and seems straightforward but am stuck really.

I try running this query

$sql="insert into employers (id, username, password, email, contact_person, company_name, location_country, location_state,     location_address, website, profile, logo, subdomain, activation_key, ipaddress) values ('', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

$params="$reg_username, $reg_password, $reg_email, $reg_contact_person, $reg_companyname, $reg_country, $reg_state, $reg_address, $reg_website, $reg_profile, $reg_logo, $reg_subdomain, $reg_activation_key, $reg_ip";

$resultobj=otherquery ($sql, "sssssssssbssss", $params);

function otherquery ($sql, $types, $params)
    {
       $connection = getConnect ();  
       $result = $connection->prepare("$sql");
       $result->bind_param($types, $params);
       $status = $result->execute();
       $result->store_result();
       $return=array('obj'=>$result, 'status' => $status, 'data'=>array());
       return $return; 
    }

and i keep getting this error:

Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of elements in type definition string doesn't match number of bind variables in /home/xyz/public_html/xyzabc.com/functions.php on line 69

What am i not counting correctly?

Thanks

  • 写回答

2条回答 默认 最新

  • duannao3819 2011-09-14 12:23
    关注

    You cannot use $params to store all your parameters: bind_param() sees only two parameters when called with $params, hence the error. You would have to pass them directly:

    $result->bind_param($types, $reg_username, $reg_password, $reg_email, $reg_contact_person, ...);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题