我正在尝试构建一个将用户插入用户表的 php 表单。用户名和用户电子邮件将通过 HTML 表单手动输入,用户密码将同时随机生成。这是我的代码:
<?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>
我得到的错误是:错误:调用本机函数'md5'时参数计数不正确。我是初学者,我从未使用过md5,有人可以帮忙吗?谢谢