How does this keep happening

Status
Not open for further replies.

Benden

maging ang maganda mamatay
Jun 4, 2010
2,280
1,480
Well Im doing the register page, and another error.

Error message: Parse error: syntax error, unexpected T_ELSE in C:\xampp\htdocs\zelo\register.php on line 45

Line 45:
PHP:
else

Full code: ( I havent finished it because it broke D:)

PHP:
<?php
echo "<h1> Register</h1>";


//form data
$submit = $_POST['submit'];
$username = strip_tags($_POST['name']);
$password = strip_tags($_POST['password']);
$repeatpassword = strip_tags($_POST['repeatpassword']);
$date = date ("Y-m-d");

if ($submit)
{

//check for existance
	if($username&&$password&&repeatpassword)
	{
	//encrypt password
		$password = md5($password);
		$repeatpassword = md5($repeatpassword);
		
		if ($password==$repeatpassword)
		{
		//check username length
		if (strlen($username)>25)	
		{
		echo "Length of username is too long";
		}
	else 
	{
	//check password length
	if (strlen($password)>15||strlen($password)<6)
	{
	echo "Password must be between 6 and 5 characters long!";
	}
		else 
		{
//register the user

echo "You've succefully registerd!";
		}


		}
		else
			echo "Your passwords do not match";
	}
	else
		echo "Please fill in <b>all</b> fields!";

}
?>
<P>


<html>

<form action'register.php' method='POST'>
	<table>
		<tr>
		<td>
			Username:
		</td>
		<td>
			<input type='text' name='name'>
		</td>
		</tr>

<tr>
		<td>
			Password:
		</td>
		<td>
			<input type='password' name='password'>
		</td>
		</tr>

<tr>
		<td>
			Repeat your password:
		</td>
		<td>
			<input type='password' name='repeatpassword'>
		</td>
		</tr>
	</table>
<p>
<input type='submit' name='submit' value='Register'>
</form>

</html>

I would love to try to fix myself but im still learning and i dont know what T_ELSE means
 

Mac

New Member
Feb 9, 2011
111
2
I done new code , which is better than this ! I coded in your horrible way (because ur a beginner (i coded that way too)) to make you understand the code , no offence .
PHP:
<?php
echo "<h1>Register</h1>";
$submit = $_POST['submit'];
$username = strip_tags($_POST['name']);
$password = strip_tags(md5($_POST['password']));
$repeatpassword = strip_tags(md5($_POST['repeatpassword']));
$date = date ("Y-m-d");
if($submit) {
    $error = "";
    if(!$username or strlen($username) > 25) {
        $error .= "Found an error to Username field.";
    }
    if(!$password or $password !== $repeatpassword or strlen($password)  > 15 or strlen($password) < 25 or !$repeatpassword) {
        $error .= "Found an error to Password or Repeat password field.";
    }
    if(!$error) {
        mysql_query("****");
    }
    else {
        echo $error;
    }
}
else {
?>
<html>

<form action'register.php' method='POST'>
    <table>
        <tr>
        <td>
            Username:
        </td>
        <td>
            <input type='text' name='name'>
        </td>
        </tr>

<tr>
        <td>
            Password:
        </td>
        <td>
            <input type='password' name='password'>
        </td>
        </tr>

<tr>
        <td>
            Repeat your password:
        </td>
        <td>
            <input type='password' name='repeatpassword'>
        </td>
        </tr>
    </table>
<p>
<input type='submit' name='submit' value='Register'>
</form>

</html>
<?php } ?>
 

Benden

maging ang maganda mamatay
Jun 4, 2010
2,280
1,480
:eek: how can codes get neater? and where did the error come from on mine? I would use yours but now i don't know where to add the rest of the coding that is needed
 

Mac

New Member
Feb 9, 2011
111
2
Error on yours -> Your not using "{ , }"
You don't have to add the rest code , my code is complete just after <?php add :
PHP:
mysql_connect("localhost", "root", "pass");
mysql_select_db("dbname");
and yeah... edit mysql_query(****) (edit ****) to your query !
 

Mac

New Member
Feb 9, 2011
111
2
yeah , your query is wrong , do it so :
PHP:
mysql_query("INSERT INTO users VALUES ('/*leave that so , id should be auto increment and primary key */', '".$username."', '".$password."')");
 

Benden

maging ang maganda mamatay
Jun 4, 2010
2,280
1,480
Still getting the same error

PHP:
<?php
echo "<h1>Register</h1>";
$submit = $_POST['submit'];
$username = strip_tags($_POST['name']);
$password = strip_tags(md5($_POST['password']));
$repeatpassword = strip_tags(md5($_POST['repeatpassword']));
$date = date ("Y-m-d");
if($submit) {
    $error = "";
    if(!$username or strlen($username) > 25) {
        $error .= "Found an error to Username field.";
    }
    if(!$password or $password !== $repeatpassword or strlen($password)  > 5 or strlen($password) < 25 or !$repeatpassword) {
        $error .= "Found an error to Password or Repeat password field.";
    }
    if(!$error) {
        mysql_query("INSERT INTO users VALUES ('".$username."', '".$password."')"); 
    }
    else {
        echo $error;
    }
}
else {
?>
<html>

<form action'register.php' method='POST'>
    <table>
        <tr>
        <td>
            Username:
        </td>
        <td>
            <input type='text' name='name'>
        </td>
        </tr>

<tr>
        <td>
            Password:
        </td>
        <td>
            <input type='password' name='password'>
        </td>
        </tr>

<tr>
        <td>
            Repeat your password:
        </td>
        <td>
            <input type='password' name='repeatpassword'>
        </td>
        </tr>
    </table>
<p>
<input type='submit' name='submit' value='Register'>
</form>

</html>
<?php } ?>
 
Status
Not open for further replies.

Users who are viewing this thread

Top