Jump to content

T_ELSE syntax error


quelle

Recommended Posts

On 25th and 29 th line

<?php
include('includes/functions.php');
session_start();

if(isset($_POST['login'])){	
if(isset($_POST['username'])){		
	if(isset($_POST['password'])){
		$query = mysql_query('SELECT * FROM users WHERE Username = $_POST["username"]') or die(mysql_error());
		$user = mysql_fetch_array($query);

		if($_POST['password'] == $user['Password']){
			echo "Uspješan login!";
			$_SESSION['user'] = $user['username'];
			header('Location: index.php');

		} else {
			echo "Provjerite login detalje!";
			include('login.php');
		}

	} else {
		echo "Password netačan!";
		include('login.php');

} else {
	echo "Username netačan!";
	include('login.php');

} else {
echo "Niste ispunili sve podatke!";
include('login.php');
}
?>

Link to comment
Share on other sites

Theres a syntax error inside your query, your missing a closing bracket also on one of the ELSE

 

try this

 

<?php


include('includes/functions.php');
session_start();

if(isset($_POST['login'])){

if(isset($_POST['username'])){		


	if(isset($_POST['password'])){



		$query = mysql_query('SELECT * FROM users WHERE Username = "'.$_POST["username"].'"') or die(mysql_error());
		$user = mysql_fetch_array($query);

		if($_POST['password'] == $user['Password']){
			echo "Uspješan login!";
			$_SESSION['user'] = $user['username'];
			header('Location: index.php');

		} else {
			echo "Provjerite login detalje!";
			include('login.php');
		}




	} else {
		echo "Password netačan!";
		include('login.php');

	}

} else {
	echo "Username netačan!";
}	include('login.php');

} else {
echo "Niste ispunili sve podatke!";
include('login.php');
}
?>


?>

Link to comment
Share on other sites

You're logic is heavily faltered and you appear to be taking no ones advice. Look at your code:

 

else {
		echo "Password netačan!";
		include('login.php');

} else {
	echo "Username netačan!";
	include('login.php');

} else {
echo "Niste ispunili sve podatke!";
include('login.php');
}

 

You have three elses in line.

 

else { } else {} else {}

 

Tell me this doesn't work and i'll tell you to take hike. :)

<?php
include('includes/functions.php');
session_start();

if(isset($_POST['login'])) {	
if(isset($_POST['username'])) {		
	if(isset($_POST['password'])){
		$query = mysql_query('SELECT * FROM users WHERE Username = $_POST["username"]') or die(mysql_error());
		$user = mysql_fetch_array($query);

		if ($_POST['password'] == $user['Password']) {
			echo "Uspješan login!";
			$_SESSION['user'] = $user['username'];
			header('Location: index.php');

		}
		else {
			echo "Provjerite login detalje!";
			include('login.php');
		}

	}
	else {
		echo "Password neta&#269;an!";
		include('login.php');

	}
}
else {
	echo "Username neta&#269;an!";
	include('login.php');

}
}
else {
echo "Niste ispunili sve podatke!";
include('login.php');
}
?>

Link to comment
Share on other sites

Try using the Notepad++ editor to write your code, it is great for quickly finding syntax errors like this because you can have it show you which IF's are connected to which ELSE's etc, and you can click a brace and it will highlight the corresponding closing brace.

 

 

if(isset($_POST['login'])){

 

On another note I'm guessing your login variable is the form's submit button? If so then you have a compatibility problem with IE. See Why isset post is not compatible with Internet Explorer.

Link to comment
Share on other sites

While what the 182guy said is true, the form could be submitted using the enter key, I disagree with using ($_SERVER['REQUEST_METHOD'] == 'POST'). I think you should simply create a hidden form field.

 

IE <input type="hidden" name="formSubmitted" value="1">

 

Then check it like:

 

if (isset($_POST['formSubmitted'])) {

}

Link to comment
Share on other sites

dAMN im really a cock sucker lolz, i closed brackets for else and didnt for whole if lol thanks tenyon for pointing out mistakes :) btw u said

I disagree with using ($_SERVER['REQUEST_METHOD'] == 'POST'). I think you should simply create a hidden form field.

 

IE <input type="hidden" name="formSubmitted" value="1">

 

Then check it like:

 

if (isset($_POST['formSubmitted'])) {

}

Can u indicate where i used that method?

Link to comment
Share on other sites

Try using the Notepad++ editor to write your code, it is great for quickly finding syntax errors like this because you can have it show you which IF's are connected to which ELSE's etc, and you can click a brace and it will highlight the corresponding closing brace.

 

 

if(isset($_POST['login'])){

 

On another note I'm guessing your login variable is the form's submit button? If so then you have a compatibility problem with IE. See Why isset post is not compatible with Internet Explorer.

Since im using firefox i didnt notice it yet but thanks for ur help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.