I'm creating a music website where users should be able to add artists, albums, and songs to a database and discuss them. However, I cannot get the data the user inputs into the signup form to transfer to my "users" table in my database. I'm not exactly sure what's wrong, but I suspect it's a problem with my syntax, because I'm not having any database connection issues. I've been searching for hours but I haven't yet found a solution. Can anyone help me?
To clarify: the error is that none of the information from the signup form is getting entered into my database after the user hits "submit"
signup.php:
<?php include 'header.php'; ?>
<form class="form" action="register.php" method="POST">
<fieldset>
<label for="firstName">First Name:</label>
<input type="text" name="firstName" placeholder="John Smith">
<br>
<label for="lastName">Last Name:</label>
<input type="text" name="lastName" placeholder="John Smith">
<br>
<label for="email">Email:</label>
<input type="email" name="email" value="some@one.com">
<br>
<label for="username">Username:</label>
<input type="text" name="username" value="helloitsme">
<br>
<label for="password">Password:</label>
<input type="password" name="password">
<br>
<label for="confirmPassword">Confirm Password:</label>
<input type="password" name="confirmPassword">
<br>
<label for="age">Age:</label>
<input type="number" name="age">
<br>
</fieldset>
<fieldset>
<input type="submit" name="submit" value="Register">
</fieldset>
</form>
register.php:
<?php
session_start();
if ($_POST["password"] != $_POST["confirmPassword"]) {
$_SESSION['signUpBadPassword'] = true;
header('Location: signup.php');
}
// Re use connection stuffs
include "db.php";
// get connection
$conn = DB::connect();
$stmt = $conn->prepare("INSERT INTO users (firstName, lastName, email, username, password, age) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->bind_param(
"sssssi",
$_POST["firstName"],
$_POST["lastName"],
$_POST["email"],
$_POST["username"],
$_POST["password"],
$_POST["age"]
);
$stmt->execute();
// Close the connection
$conn->close();
header('Location: index.php');
?>
And db.php:
<?php
class DB
{
public static function connect()
{
$hostname = 'localhost';
$username = 'user';
$password = 'password';
$dbName = 'dbname';
$connection = new mysqli($hostname, $username, $password, $dbName);
if ($connection->connect_error) {
die('Failed to connect');
}
return $connection;
}
}