hey whenever i input data into my sign up form and click submit… i am getting nothing on the screen, and nothing is going into my data base.
Can someone check my code and see where I have gone wrong please?
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="signup.css">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>****************</title>
<link rel="stylesheet" href="./signup.css">
<script src="./index.js" defer></script>
</head>
<button onclick= "window.location.href = 'index.php';">Go Back</button>
<body>
<div class="container">
<div class="h1">
<h1>******************</h1>
<section class="signup.css">
<h2> Sign Up</h2>
<form action= "Signup.inc.php" method="post" novalidate>
<input type="text" name="name" placeholder="Full name...">
<input type="text" name="email" placeholder="Email...">
<input type="password" name="pwd" placeholder="Password...">
<input type="password" name="pwdrepeat" placeholder="Repeat Password...">
<button type="submit" name="submit">Sign Up</button>
</form>
<?php
// Error messages
if (isset($_GET["error"])) {
if ($_GET["error"] == "emptyinput") {
echo "<p>Fill in all fields!</p>";
}
else if ($_GET["error"] == "invaliduid") {
echo "<p>Choose a proper username!</p>";
}
else if ($_GET["error"] == "invalidemail") {
echo "<p>Choose a proper email!</p>";
}
else if ($_GET["error"] == "passwordsdontmatch") {
echo "<p>Passwords doesn't match!</p>";
}
else if ($_GET["error"] == "stmtfailed") {
echo "<p>Something went wrong!</p>";
}
else if ($_GET["error"] == "usernametaken") {
echo "<p>Username already taken!</p>";
}
else if ($_GET["error"] == "none") {
echo "<p>You have signed up!</p>";
}
}
?>
<?php
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;
}
function invalidUid($username) {
$result;
if (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
$result = true;
}
else {
$result = false;
}
return $result;
}
function invalidEmail($email) {
$result;
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$result = true;
}
else {
$result = false;
}
return $result;
}
function pwdMatch($pwd, $pwdrepeat) {
$result;
if ($pwd !== $pwdrepeat) {
$result = true;
}
else {
$result = false;
}
return $result;
}
function uidExists($conn, $username) {
$sql = "SELECT * FROM users WHERE usersUid = ? OR usersEmail = ?;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: ../Signup.php?error=stmtfailed");
exit();
}
mysqli_stmt_bind_param($stmt, "ss", $username, $username);
mysqli_stmt_execute($stmt);
$resultData = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($resultData)) {
return $row;
}
else {
$result = false;
return $result;
}
mysqli_stmt_close($stmt);
}
function createUser($conn, $name, $email, $username, $pwd) {
$sql = "INSERT INTO users (usersName, usersEmail, usersUid, usersPwd) VALUES (?, ?, ?, ?);";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: ../Signup.php?error=stmtfailed");
exit();
}
$hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
mysqli_stmt_bind_param($stmt, "ssss", $name, $email, $username, $hashedPwd);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
mysqli_close($conn);
header("location: ../Signup.php?error=none");
exit();
}
function emptyInputLogin($username, $pwd) {
$result;
if (empty($username) || empty($pwd)) {
$result = true;
}
else {
$result = false;
}
return $result;
}
function loginUser($conn, $username, $pwd) {
$uidExists = uidExists($conn, $username);
if ($uidExists === false) {
header("location: ../login.php?error=wronglogin");
exit();
}
$pwdHashed = $uidExists["usersPwd"];
$checkPwd = password_verify($pwd, $pwdHashed);
if ($checkPwd === false) {
header("location: ../login.php?error=wronglogin");
exit();
}
elseif ($checkPwd === true) {
session_start();
$_SESSION["userid"] = $uidExists["usersId"];
$_SESSION["useruid"] = $uidExists["usersUid"];
header("location: ../index.php?error=none");
exit();
}
}
<?php
if (isset($_POST["submit"])) {
$name = $_POST["name"];
$email = $_POST["email"];
$pwd = $_POST["pwd"];
$pwdRepeat = $_POST["pwdrepeat"];
require_once "dbh.inc";
require_once 'functions.inc.php';
if (emptyInputSignup($name, $email, $username, $pwd, $pwdRepeat) !== false) {
header("location: ../Signup.php?error=emptyinput");
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) !== false) {
header("location: ../Signup.php?error=usernametaken");
exit();
}
createUser($conn, $name, $email, $username, $pwd);
} else {
header("location: ../Signup.php");
exit();
}
<?php
$servername = "localhost";
$dBUsername = "root";
$dBPassword = "";
$dBname = "Signup_db";
$conn = mysqli_connect($servername,$dBUsername,$dBPassword,$dBname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}