I am learning PHP and using it with my knowledge of SQL and HTML to make a login system. However when I reached the point where I wanted to test and see the input validation I put in for the HTML input fields I got the error.
Parse error: syntax error, unexpected end of file in /home/neil2/public_html/login/register2.php on line 170
I researched the problem and have found out that this happens mostly because of missing a bracket or semicolon in the PHP script however I have looked and cannot seem to find it. I tried putting the code into Notepad++ to show me the beginning and end of the if statements and functions however there doesn't appear to be any missing and I think that it maybe something else. Any help is appreciated.
EDIT: The code is still being built so they maybe more errors in there but I was not able to get rid of them before posting here due to this error.
<?php
$username = htmlspecialchars($_POST['username']);
$password = htmlspecialchars($_POST['password']);
$password2 = htmlspecialchars($_POST['retypepassword']);
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
$secquest = htmlspecialchars($_POST['secrquest']);
$secans = hash("sha512", $_POST['secrans'], "true");
include_once("php/db_connect.php");
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (empty($username))
{
$userempty = "Please enter a username!";
} else {
checkdata ($username);
}
if (empty($name))
{
$nameempty = "Please enter your name!";
} else {
checkdata ($name);
}
if (empty($email))
{
$emailempty = "Please enter your email address!";
} else {
checkdata ($email);
}
if (empty($secquest))
{
$secqempty = "Please enter a security question!";
} else {
checkdata ($secquest);
}
}
$usernamecomplete;
$usernameerror;
Usernamestuff ($dbconnect, $username, $usernamecomplete, $usernameerror);
$passwordcomplete;
$passworderror;
Passwordstuff ($password, $password2, $secpass, $passwordcomplete, $passworderror);
function checkdata ($data)
{
$data = trim($data);
$data = stripslashes($data);
return $data;
}
function Usernamestuff ($dbconnect, $user, $uc, $ue)
{
$usercheck = "SELECT username FROM members WHERE username='$user'";
$userq = mysqli_query($dbconnect, $usercheck);
$numuser = mysqli_num_rows($userq);
if (numuser == 0)
{
$uc = TRUE;
$ue = 0;
} else {
$uc = FALSE;
$ue = 1;
}
}
function Passwordstuff ($pw, $pw2, $scpw, $pc, $pe)
{
$same = strcmp($pw, $pw2);
if ($same == 0)
{
$scpw = hash("sha256", $pw, "true");
$pc = TRUE;
$pe = 0;
} else {
$pc = FALSE;
$pe = 1;
}
function Emailstuff ($dbconnect, $email, $ec, $er)
{
$emailcheck = "SELECT email FROM members WHERE email='$email'";
$emailq = mysqli_query($dbconnect, $emailcheck);
$numemail = mysqli_num_rows($emailq);
if ($numemail == 0)
{
$ec = TRUE;
$er = 0;
} else {
$ec = FALSE;
$er = 1;
}
}
function Insertmember ($dbconnect, $user, $scpw, $name, $email, $scqu, $scan)
{
$insertinfo = "INSERT INTO members VALUES (NULL, '$username', '$scpw', '$name', '$email', '$scqu', '$scan', CURRENT_TIMESTAMP); ";
mysqli_query($dbconnect, $insertinfo);
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Register</title>
<style type="text/css">
#Username {
width: 141px;
}
#Password {
width: 141px;
}
#Name {
width: 141px;
}
#Email {
width: 141px;
}
#SecurityQuestion {
width: 260px;
}
#SecurityAnswer {
width: 141px;
}
#regiser {
width: 89px;
}
</style>
</head>
<body style="height: 221px">
<form id="register_form" method="POST" action="register2.php">
<div>
<fieldset>
<legend>Register</legend>
* Required Field
<input id="Username" type="text" name="username" placeholder="Username" />
<span class="error">* <?php echo $userempty; ?></span>
<br />
<br />
<input id="Password" type="password" name="password" placeholder="Password" /> *
<br />
<br />
<input id="Password" type="password" name="retypepassword" placeholder="Retype Password" /> *
<br />
<br />
<input id="Name" type="text" name="name" placeholder="Your name" /> *
<span class="error">* <?php echo $nameempty; ?></span>
<br />
<br />
<input id="Email" type="text" name="email" placeholder="Email" />
<span class="error">* <?php echo $emailempty; ?></span>
<br />
<br />
<input id="SecurityQuestion" type="text" name="secrquest" value="Mothers Maiden name?" /> *
<span class="error">* <?php echo $secqempty; ?></span>
<br />
<br />
<input id="SecurityAnswer" type="text" name="secrans" placeholder="Security Question Answer" /> *
<br />
<br />
<input id="register" type="submit" value="Register" />
<br />
</fieldset>
</div>
</form>
</body>
</html>