Hello i've got a problem with "else" it says unexpected T_ELSE but i have no idea what could be wrong here

if ($id == "funkcijos")
{
    if($vardas != "" && $slaptazodis != "" && $el_pastas != "")
    {

        $query = "INSERT INTO vartotojai SET vardas = '$vardas', slaptazodis = '$slaptazodis', el_pastas = '$el_pastas', avataras = '$avataras', parasas = '$parasas'";
        mysql_query($query);

        
        print "Welcome to the Naruto-Clash. <a href='registracija_ir_login.php'>Log In.</a>";
    }
    else
    {
    print "Empty fields.";
    }
               //[B]Here[/B]
		else
		{
		if ($_POST['Naruto'] == "ON")
		{
		
		$query = "INSERT INTO vartotojai SET character = 'Naruto'";
        mysql_query($query);
				}
		}

Recommended Answers

All 7 Replies

Member Avatar for diafol

You need another '}' before the second 'else'.

<?php
if ($id == "funkcijos"){
    if($vardas != "" && $slaptazodis != "" && $el_pastas != ""){
        $query = "INSERT INTO vartotojai SET vardas = '$vardas', slaptazodis = '$slaptazodis', el_pastas = '$el_pastas', avataras = '$avataras', parasas = '$parasas'";
        mysql_query($query);
        print "Welcome to the Naruto-Clash. <a href='registracija_ir_login.php'>Log In.</a>";
    }else{
	print "Empty fields.";
    }
               //Here
}else{
	if ($_POST['Naruto'] == "ON"){
		$query = "INSERT INTO vartotojai SET character = 'Naruto'";
                mysql_query($query);
	}
}
?>

Sorry for reformatting your code, but braces on their own lines really confuse the hell out of me - especially if the indentation has gone to pot.

Thanks for that but there's another problem

if ($_POST['Naruto'] == "ON"){
		$query = "INSERT INTO vartotojai SET character = 'Naruto'";
                mysql_query($query);

it supposed to insert "Naruto" into database when a checkbox is checked but nothing is happening?

Member Avatar for diafol
if(isset($_POST['Naruto'])){

and

"INSERT INTO vartotojai SET `character` = 'Naruto'";

ok last problem :O the query in the end doesnt work i tried everything (1st one works)

<?php
if ($id == "funkcijos"){
    if($vardas != "" && $slaptazodis != "" && $el_pastas != ""){
        $query = "INSERT INTO vartotojai SET vardas = '$vardas', slaptazodis = '$slaptazodis', el_pastas = '$el_pastas', avataras = '$avataras', parasas = '$parasas'";
        mysql_query($query);
        print "Welcome to the Naruto-Clash. <a href='registracija_ir_login.php'>Log In.</a>";
    }else{
	print "Empty fields.";
    }
               //Here
}else{
	if(isset($_POST['Naruto'])){
//[B]HERE[/B]
		$query = "INSERT INTO vartotojai SET character = 'Naruto'";
                mysql_query($query);
	}
}
?>
Member Avatar for diafol

Perhaps you need to place the fieldname "character" in backticks as I suggested. I think "character" is a reserved word in SQL - I may be wrong.
So:

`character`

nope nothing changed

should i post you the whole code it might be some mistakes somewhere else?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.