I am following a tutorial on how to create a sign up page in php, but I keep getting an empty input error when I type results into the sign up section. I think that is because I am getting an error that my $result variable is undefined. I have re-watched the tutorial many times to find any typos but have ended up just exhausting myself.
This is my .signup.inc.php file
<?php
// no ending tag when only php code
if (isset($_POST["submit"])) {
//$ signifies a variable
$name = $_POST["name"];
$email = $_POST["email"];
$username = $_POST["uid"];
$pwd = $_POST["pwd"];
$pwdrepeat = $_POST["pwdrepeat"];
require_once 'dbh.inc.php';
require_once 'functions.inc.php';
if(emptyInputSignup($name, $email, $username, $pwd, $pwdrepeat) !== false) {
header("location: ../signup.php?error=emptyinput");
exit();
}
if(invalidUid($username) !== false) {
header("location: ../signup.php?error=invaliduid");
exit();
}
if(invalidEmail($email) !== false) {
header("location: ../signup.php?error=invalidemail");
exit();
}
if(pwdMatch($pwd, $pwdRepeat) !== false) {
header("location: ../signup.php?error=passwordsdontmatch");
exit();
}
if(Uidexists($conn, $username, $email) !== false) {
header("location: ../signup.php?error=usernametaken");
exit();
}
createUser($conn, $name, $email, $username, $pwd);
}
else {
header("location: ../signup.php");
exit();
}
This is the start of my functions.inc.php file where the undefined $result occurs.
function emptyInputSignup($name, $email, $username, $pwd, $pwdrepeat) {
$result;
if(empty($name) || empty($email) || empty($username) ||
empty($pwd) || empty($pwdrepeat)) {
$result = true;
}
else {
$result = false;
}
return $result;
}
CodePudding user response:
can you just remove the first $result in the function and check again.
function emptyInputSignup($name, $email, $username, $pwd, $pwdrepeat) {
if(empty($name) || empty($email) || empty($username) ||
empty($pwd) || empty($pwdrepeat)) {
$result = true;
}
else {
$result = false;
}
return $result;
}
also you can do it shorthand
function emptyInputSignup($name, $email, $username, $pwd, $pwdrepeat) {
return (empty($name) || empty($email) || empty($username) ||
empty($pwd) || empty($pwdrepeat)) ?? false;
}