gpt4 book ai didi

php - fatal error : Uncaught ArgumentCountError: Too few arguments to function

转载 作者:可可西里 更新时间:2023-11-01 13:33:06 24 4
gpt4 key购买 nike

我知道有一些与此相关的问题,但有 C++ 或其他语言的问题。我得到这个错误,我不确定我的功能有什么问题。

我的错误是这样的:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function User::register(), 2 passed in C:\xampp\htdocs\register.php on line 39 and exactly 5 expected in C:\xampp\htdocs\classes\users.php:22 Stack trace: #0 C:\xampp\htdocs\register.php(39): User->register('ds', 'dsssssss') #1 {main} thrown in C:\xampp\htdocs\classes\users.php on line 22

我的功能是:

public function register($name, $surname, $username, $password, $email)
{
try {
$newPassword = password_hash($password, PASSWORD_DEFAULT);

$stmt = $this->conn->prepare("INSERT INTO user(name, surname, username, password, email)
VALUES(:name, :surname, :username, :password, :email)");

$stmt->bindParam(":name", $name);
$stmt->bindParam(":surname", $surname);
$stmt->bindParam(":username", $username);
$stmt->bindParam(":password", $password);
$stmt->bindParam(":password", $password);
$stmt->bindParam(":email", $email);

$stmt->execute();

return $stmt;
}
catch(PDOException $e) {
echo $e->getMessage();
}
}

Register.php文件:

  <!DOCTYPE html>
<?php
session_start();
require_once('classes/users.php');
$user = new User();

if($user->isLoggedIn()!="") {
$user->redirect('home.php');
}

if(isset($_POST['submit'])) {
$name = strip_tags($_POST['name']);
$surname = strip_tags($_POST['surname']);
$username = strip_tags($_POST['username']);
$password = strip_tags($_POST['password']);
$email = strip_tags($_POST['email']);

if($name=="") {
$error[] = "provide username !";
} else if($surname=="") {
$error[] = "Provide surname!";
} else if ($username =="") {
$error[] = "Provide username!";
} else if($password=="") {
$error[] = "provide password !";
} else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error[] = 'Please enter a valid email address !';
} else if(strlen($password) < 6){
$error[] = "Password must be atleast 6 characters";
} else {
try {
$stmt = $user->runQuery("SELECT username FROM user WHERE username=:username");
$stmt->execute(array(':username'=>$username));
$row=$stmt->fetch(PDO::FETCH_ASSOC);

if($row['username']==$username) {
$error[] = "sorry username already taken !";
} else {
if($user->register($username,$password)){
$user->redirect('register.php?joined');
}
}
}
catch(PDOException $e) {
echo $e->getMessage();
}
}
}
?>
<html>
<head>
<meta charset="UTF-8">
<title>
</title>
</head>
<body>
<div class="form">
<form method ="post" action="register.php">
<h3 class = "signup"> Sign Up </h3>
<?php
if(isset($error)) {
foreach($error as $error)
{
?>
<div class="alert alert-danger">
<i class="glyphicon glyphicon-warning-sign"></i> &nbsp; <?php echo $error; ?>
</div>
<?php
}
}
else if(isset($_GET['joined']))
{
?>
<div class="alert alert-info">
<i class="glyphicon glyphicon-log-in"></i> &nbsp; Successfully registered <a href='index.php'>login</a> here
</div>
<?php
} ?>

Vardas:<br>
<input type="text" name="name" id="name" placeholder="Vardas" required>
<br>
Pavardė:<br>
<input type="text" name="surname" id="surname" placeholder="Pavardė" required>
<br>
Prisijungimo vardas:<br>
<input type="text" name="username" id="username" placeholder="Prisijungimo vardas" required>
<br>
Slaptažodis:<br>
<input type="password" name="password" id="password" placeholder="Slaptažodis" required>
<br>
El. pašto adresas: <br>
<input type="email" name="email" id="email" placeholder="El. pašto adresas" required>
<br><br>
<div class ="div">
<input type="submit" name="submit" id="submit" value="Registruotis">
<br><br>
<label>Have an account? <a href="index.php">Sign In</a></label>
</form>
</div>
</body>

感谢您的帮助!

最佳答案

在 php 7 中代替:

    public function register($name, $surname, $username, $password, $email)
{
...

使用:

public function register($name = null, $surname = null, $username = null, $password = null, $email = null)
{
...

关于php - fatal error : Uncaught ArgumentCountError: Too few arguments to function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43521468/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com