CREATE DATABASE `user` 
use user
CREATE TABLE `userinfo` (
  `userid` int(11) NOT NULL auto_increment,
  `username` varchar(10) default NULL,
  `pwd` varchar(10) default NULL,
  PRIMARY KEY  (`userid`)
)
上面这是数据库代码
<?php
$link = mysqli_connect('localhost', 'root', '123', 'user');

if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$sql="insert into userinfo (username,pwd)  values (?,?)";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_bind_param($stmt, $name,$p);

$name="aa";
$p="aa";

mysqli_stmt_execute($stmt); printf("%d Row inserted.\n", mysqli_stmt_affected_rows($stmt));

mysqli_stmt_close($stmt);

mysqli_query($link, "delete from userinfo where username='admin'");
printf("%d Row deleted.\n", mysqli_affected_rows($link));

mysqli_close($link);
?> 
上面这是php代码结果报错为:Warning: mysqli_stmt_bind_param() [function.mysqli-stmt-bind-param]: Number of elements in type definition string doesn't match number of bind variables in D:\Program Files\php\AppServ\www\lianxi\dblogin.php on line 68
0 Row inserted. 0 Row deleted. 这是怎么回事?请帮忙看一下

解决方案 »

  1.   

    手册:<?php
    $mysqli = new mysqli('localhost', 'my_user', 'my_password', 'world');/* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }$stmt = $mysqli->prepare("INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
    $stmt->bind_param('sssd', $code, $language, $official, $percent);$code = 'DEU';
    $language = 'Bavarian';
    $official = "F";
    $percent = 11.2;/* execute prepared statement */
    $stmt->execute();printf("%d Row inserted.\n", $stmt->affected_rows);/* close statement and connection */
    $stmt->close();/* Clean up table CountryLanguage */
    $mysqli->query("DELETE FROM CountryLanguage WHERE Language='Bavarian'");
    printf("%d Row deleted.\n", $mysqli->affected_rows);/* close connection */
    $mysqli->close();
    ?> 
      

  2.   

    bool mysqli_stmt_bind_param ( mysqli_stmt stmt, string types, mixed &var1 [, mixed &...] )
    注意参数
      

  3.   


    bool mysqli_stmt_bind_param ( mysqli_stmt stmt, string types, mixed &var1 [, mixed &...] )第二个参数是第三个参数的类型吗?那我这一个绑定参数是怎么写?我有点晕,请指点,
      

  4.   

    终于找到答案了$q = "select firstname,lastname from users where uid = ?"; 
    $stmt = mysqli_prepare($dbc,$q);  
    mysqli_stmt_bind_param($stmt,'i',$id);
    其中i是Integer就是$id的类型字母                    表示绑定的值类型
    d                       Decimal
    i                       Integer
    b                       Blob (二进制类型)
    s                       所有其它类型$q = "select uid,firstname from users where email=? AND pass=SHA1(?)";
    $stmt = mysqli_prepare($dbc,$q);
    mysqli_stmt_bind_param($stmt,'ss',$e,$p);其中ss,第一个s是$e的数据类型:其它类型(string) 第二个s是$p的数据类型:其它类型(string)