Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

?
Lv 4

whats wrong with this PHP code?

hi

Ive made a register and login page, you can view the register page here >> http://www.techempirestest.net16.net/register.php

However when i press "Register" i get this error:

Parse error: syntax error, unexpected T_ELSE in /home/a4264749/public_html/register.php on line 84

here is line 84: else

and here is my code

?php

echo "<h1>Register</h1>";

$submit = $_POST['submit'];

//form data

$firstname = strip_tags($_POST['firstname']);

$surname = strip_tags($_POST['surname']);

$username = $_POST['username'];

$password = strip_tags($_POST['password']);

$confirmpassword = strip_tags($_POST['confirmpassword']);

$date = date("y-m-d");

if ($submit)

{

//check for existance

if ($firstname&&$surname&&$username&&$password&&$confirmpassword)

{

if ($password==$confirmpassword)

{

//check char length of username and fullname

if (strlen($username)>25||strlen($firstname)>25)

{

echo "Length of Username or First name is too long";

}

else

{

//check password length

if (strlen($password)>25||strlen($password)<6)

{

echo "Password must be between 6 and 25 characters";

}

else

{

//register the user

//encrypt password

$password = md5($password);

$confirmpassword = md5($confirmpassword);

//open database

$connect = mysql_connect("hostnameremoved","removed","passwordremoved");

mysql_select_db("removed"); //select database

$queryreg = mysql_query("INSERT INTO users VALUES ('','$firstname','$username','$password','$date')");

die ("You have been registered! <a href='login.html'>Click here</a>to login ");

}

}

}

else

echo "Your passwords do not match!";

{

}

else

echo "Please fill in <b>all</b> fields!";

}

}

?>

<html>

<head>

<style type="text/css">

a:link {color:blue;text-decoration:none;}

a:visited {color:red;text-decoration:none;}

a:hover {color:orange;text-decoration:underline;…

</style>

</head>

<body>

<p>

<form action='register.php'>

<table>

<td>

<tr>

First Name

</tr>

<tr>

<input type='text' name='first name' value='<?php echo $firstname ?>'

</td><br>

<tr>

Surname

</tr>

<tr>

<input type='text' name='surname' value='<?php echo $surname ?>'

</tr><br>

<tr>

Desired Username:

</tr>

<tr>

<input type='text' name='username' value='<?php echo $username ?>'

</tr><br>

<tr>

Choose a password:

</tr>

<tr>

<input type='password' name='password'>

</tr>

<br>

<tr>

Confirm password:

</tr>

<tr>

<input type='password' name='confirm password'>

</tr>

<br>

<input type='submit' name='submit' value='Register'>

</td>

</table>

</form>

</body>

</html>

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    Hi there,

    It looks like your missing an opening curly brace at

    else

    echo "Your passwords do not match!";

    EDIT: Sorry you have your statement before the opening Brace of the else statement.

    Update your code if you still have errors

    try adding "{" right after else in both cases. I took a quick look at it so I am not sure if that would fix it.

    TIPS:

    If you see an error with T_ELSE or T_IF. It means there is something wrong with your IF or ELSE conditions.

    Also put comments on your closing brackets in complex if and else statements that nest quite a bit. This will help you visualize where the problem might be. For example

    if(i_am_awesome) {

    if(i_gots_money) {

    }//end money condition

    else {

    }//end no money condition

    } //end awesome condition

    Source(s): my Portfolio Yo - http://jmcmurray.com/
  • Anonymous
    4 years ago

    that is much less demanding to debug while we are able to be sure this on line. And, please, do away with that midsection tag and validate your code! do no longer in uncomplicated terms use HTML5 because of the fact that is cool; use it the astonishing way!

Still have questions? Get your answers by asking now.