I'm stuck on this register form. I have an error with this code:
Fatal error: Call to undefined function test() in C:\wamp\www daiegister.php on line 21
I can't figure it out what the error is or where i can fix it.
Php:
include('db.php');
$message = '';
$x = '';
$t='';
$num1 = '';
$num2 = '';
$num3 = '';
if(isset($_POST['submit'])){
//pra randum number
$adminNo = $num1 . $num2 . $num3;
$name = trim($_POST['name']);
$username = trim($_POST['username']);
$password = trim($_POST['password']);
$function = "admin";
$list = test($username);
foreach($list as $t){
$x = $t['userName'];
}
if(strlen($username) < 6){ //IF THE USERNAME LENGTH IS LESSER THAN 5
$message = 'Username must be greater than 5 characters.';
} else if($username === $x){ //IF THE USERNAME IS ALREADY TAKEN
$message = 'Username is already taken.';
} else {
$message = register($adminNo, $username, $password, $fullname, $function);
echo"<script>alert('Successfully registered!');
window.location='login.php'
</script>";
}
}
Html:
<body>
<form method = "post">
<input type="text" placeholder="fullname" name="name" /><br>
<input type="text" placeholder="username" name="username" /><br>
<input type="password" placeholder="password" name="password" /><br>
<input type="submit" name="submit" value="register" />
<?php echo $message;?>
</form>
</body>
you may want to include
or require
the file that has this function or add it to the top, before the if statement
function test() {}
function register() {}
checkout http://www.laravel.com it may help you build better websites
The problem with your code is exactly what the error says; you're calling an undefined function named test()
.
You try to define a variable $list
and give it the value test($username)
. What you are doing here is passing $username
to the test()
method.
According to your code $username
should contain something passed through the POST global variable but you didn't actually define test()
anywhere.
I'm not sure what you're trying to accomplish seeing as a function named "test" could be doing anythning.
Either remove the line $list = test($username);
from your code or define test()
There is no $fullname
..
$message = register($adminNo, $username, $password, $name, $function);
No description of test()
.