Hello,
I am working on some code, trying to get a system setup where a user can login either as basic user or admin. I am getting this error: Parse error : syntax error, unexpected end of file in C:\Program Files\Projects\register.php on line 156
Here is the code
<?php
// Include config file
require_once “config.php”;
// Define variables and initialize with empty values
$Name1 = $password = $confirm_password = "";
$userid="1";
$username_err = $password_err = $confirm_password_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// Validate username
if(empty(trim($_POST["Name"])))
{
$username_err = "Please enter a username.";
}
else
{
// Prepare a select statement
$sql = "SELECT Name FROM users WHERE Name = ?";
if($stmt = mysqli_prepare($link, $sql))
{
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt,"s",$param_Name);
// Set parameters
$param_Name = trim($_POST["Name"]);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt))
{
/* store result */
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 1)
{
$username_err = "This username is already taken.";
}
else
{
$Name1 = trim($_POST["Name"]);
}
}
else
{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
mysqli_stmt_close($stmt);
}
// Validate password
if(empty(trim($_POST["password"]))){
$password_err = "Please enter a password.";
} elseif(strlen(trim($_POST["password"])) < 6){
$password_err = "Password must have atleast 6 characters.";
} else{
$password = trim($_POST["password"]);
}
// Validate confirm password
if(empty(trim($_POST["confirm_password"]))){
$confirm_password_err = "Please confirm password.";
}
else
{
$confirm_password = trim($_POST["confirm_password"]);
if(empty($password_err) && ($password != $confirm_password)){
$confirm_password_err = "Password did not match.";
}
// Check input errors before inserting in database
if(empty($username_err) && empty($password_err) && empty($confirm_password_err))
{
// Prepare an insert statement
$sql = "INSERT INTO users (Name, password,userid) VALUES (?, ?,?)";
if($stmt = mysqli_prepare($link, $sql))
{
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt,"ss", $param_Name, $param_password,$param_userid);
// Set parameters
$param_Name = $Name1;
$param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
$param_userid= $userid;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt))
{
// Redirect to login page
header("location: login2.php");
}
else
{
echo "Something went wrong. Please try again later.";
}
}
// Close statement
mysqli_stmt_close($stmt);
// Close connection
mysqli_close($link);
?>
Sign Up body{ font: 14px sans-serif; } .wrapper{ width: 350px; padding: 20px; }Sign Up
Please fill this form to create an account.
" method="post">Already have an account? Login here.