Good day. I would like to ask what's wrong with my codes. These already worked in a website that we made with my mate but as I run "register.php", I cannot insert data to my table named 'accounts'. Thanks in advance. Here are the codes:
connect.php
<?php
//Callback function for connecting the website to the accounts database.
$connect = mysqli_connect('localhost', 'root', '');
if (!$connect){
die("Database Connection Failed" . mysqli_error($connect));
}
//Selects the database
$select_database = mysqli_select_db($connect, 'users');
if (!$select_database){
die("Database Selection Failed" . mysqli_error($connect));
}
register.php
<?php
session_start();
require('connect.php');
//If the values are posted, insert them into the database.
if (isset($_POST['username']) && isset($_POST['pass'])){
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['pass'];
$passwordauth = $_POST['passwordauth'];
if($password == $passwordauth){
$password = hash ( 'sha256' , $password ); // hash function creates
an encrypted code form the $password for security considerations
$query = "INSERT INTO accounts (username, password, email) VALUES
('$username', '$password', '$email')";
$result = mysqli_query($connect, $query);
if($result){
$msg = "User Created Successfully.";
}
else{
$msg ="User Registration Failed";
}
}
else
{
$msg ="Password does not match.";
}
}