【问题标题】:Warning: mysqli::prepare() expects exactly 1 parameter, 2 given in警告:mysqli::prepare() 只需要 1 个参数,2 个在
【发布时间】:2013-07-31 02:03:00
【问题描述】:

我被困在这里它给了我这个错误=(有什么帮助吗?

$link = mysql_connect("localhost","odyssexxxxxx","xxxxxxxx")
or die ("Could not connect :" . mysql_error());

// db
mysql_select_db("odysseus_matchcode",$link);


// ejecucion del query

if ($insert_stmt = $mysqli->prepare("UPDATE members SET (nombre, apellido, username, email, password, salt, telefono) VALUES (?, ?, ?, ?, ?, ?, ?) WHERE `cedula` = '$cedula'",$link)) {    
   $insert_stmt->bind_param('sssssss', $nombre, $apellido, $username, $email, $password, $random_salt, $telefono); 
    // Execute the prepared query.
   $insert_stmt->execute();
}

【问题讨论】:

  • 您混合使用了mysqlmysqli 函数。
  • 你的代码中的$mysqli是什么?

标签: php sql forms


【解决方案1】:

您正在混合您的 API 和样式。

mysql_connectmysql_select_db 与 MySQLi 属于不同的库。

试试看:

$mysqli = new mysqli("host","user","password","database"); 

代替:

$link = mysql_connect("localhost","odyssexxxxxx","xxxxxxxx")
or die ("Could not connect :" . mysql_error());

// db
mysql_select_db("odysseus_matchcode",$link);

然后将你准备好的语句更改为:

if ($insert_stmt = $mysqli->prepare("UPDATE members SET (nombre, apellido, username, email, password, salt, telefono) VALUES (?, ?, ?, ?, ?, ?, ?) WHERE `cedula` = ?")) { 

   $insert_stmt->bind_param('ssssssss', $nombre, $apellido, $username, $email, $password, $random_salt, $telefono,$cedula); 

我还建议阅读手册:http://uk1.php.net/manual/en/book.mysqli.php

开始于:

Mysqli::Construct 了解如何正确初始化 MySQLi 类,然后继续准备语句 stmt::FunctionName

【讨论】:

  • '$cedula' > SQL 注入。
  • @CORRUPT 感谢您指出这一点。如果打开严格报告,OP 应该对准备好的语句有错误。不过谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多