douye8500 2013-01-30 12:22
浏览 143
已采纳

插入表 - 错误:调用本机函数'md5'时参数计数不正确

I'm trying to build a php form that will insert users into users table. User name and User email will be entered manually via a HTML form and User Password will be generated randomly at the same time. This is my code:

<?php
if (isset($_POST['insert'])) {
require_once 'dblogin.php'; 

  $OK = false;
  $conn = new mysqli ($host, $user, $password, $database) or die("Connection Failed");
  $stmt = $conn->stmt_init();


  $sql = 'INSERT INTO users (user_email, user_name, user_password)
          VALUES(?, ?, des_encrypt(substring (md5(rand(),1,8))))';
  if ($stmt->prepare($sql)) {
    // bind parameters and execute statement
    $stmt->bind_param('sss', $_POST['user_email'], $_POST['user_name'], $_POST['user_password']);
    // execute and get number of affected rows
    $stmt->execute();
    if ($stmt->affected_rows > 0) {
      $OK = true;
    }
  }
  if ($OK) {
    header('Location: confirm.php');
    exit;
  } else {
    $error = $stmt->error;
  }
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Add User</title>
</head>

<body>
<h1>Add User</h1>
<?php if (isset($error)) {
  echo "<p>Error: $error</p>";
} ?>
<form id="form1" method="post" action="">
  <p>
    <label for="user_email">User email:</label>
    <input name="user_email" type="text" class="widebox" id="user_email">
  </p>
    <p>
    <label for="user_name">User name:</label>
    <input name="user_name" type="text" class="widebox" id="user_name">
  </p>
  <p>
    <input type="submit" name="insert" value="Register New User" id="insert">
  </p>
</form>
</body>
</html>

The error I'm getting is: Error: Incorrect parameter count in the call to native function 'md5'. I'm a beginner and I have never used md5, could someone please help ? Thanks

  • 写回答

3条回答 默认 最新

  • dongzan2740 2013-01-30 12:30
    关注

    Problem is here :

    $sql = 'INSERT INTO users (user_email, user_name, user_password)
              VALUES(?, ?, des_encrypt(substring (md5(rand(),1,8))))';
    

    MD5 takes only one parameter - the string to be hashed.

    Try this :

        $sql = 'INSERT INTO users (user_email, user_name, user_password)
              VALUES(?, ?, des_encrypt(substring(md5(rand()),1,8)))';    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services