My data input to a registration form is not being added to my database. The code is below.
The first set of php is within the html file with the html form. The last php code I have included is registrationUpload.php.
<?php
include ('registrationUpload.php');
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
if (!$_POST['submit']) {
echo "all fields are required";
}
else {
$sql = "INSERT into accounts (username, password, email, firstname, lastname)
values ('$username','$password','$email','$firstName','$lastName')";
if (mysqli_query($conn, $sql) {
echo "data creation successful";
}
else {
echo "something went wrong";
}
}
?>
<form action = "registrationUpload.php" method = "POST">
<p>Username</p>
<input type = "text" name = "username" placeholder = "Enter Username">
<p>Password</p>
<input type = "password" name = "password" placeholder = "Enter Password">
<p>Email</p>
<input type = "email" name = "email" placeholder = "Enter Email Address">
<p>First name</p>
<input type = "firstName" name = "firstName" placeholder = "Enter your first name">
<p>Last name</p>
<input type = "lastName" name = "lastName" placeholder = "Enter your last name">
<input type = "submit" name = "submit" value = "Login"><br>
registrationUpload.php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "5091632u";
$db = "registrations_db";
$conn = new mysqli ($dbhost, $dbuser, $dbpass, $db);
if($conn->connect_error){
echo "connection failed";
}
else {
"connection was successful";
}