0
<?php 

$Servername="localhost";
$Username="root";
$Password="";
$dbname="db_unity";

$connection=new mysqli($Servername,$Username,$Password,$dbname);

if(!$connection){

die("connection failed".mysqli_connect_error());

    }

else
{

    echo "connected";
} 

}
?>

Hello to everyone.When i write this code in sublime Text i have this error:

Parse error: syntax error, unexpected '}', expecting end of file in C:\xampp\htdocs\unity\connection.php on line 22

Please help Why?!!!!!

hungrykoala
  • 1,083
  • 1
  • 13
  • 28
Sajjad
  • 9
  • 1
  • You have 2 `{` and 3 `}` so you have an extra `}` :) The rule of thumb for curly braces is that they should be of equal pairs. no more no less :) – hungrykoala Jun 28 '18 at 04:08
  • there is extra '}' at the end of file before end of PHP tag '?>' – Jaydp Jun 28 '18 at 04:08
  • 1
    Possible duplicate of [PHP parse/syntax errors; and how to solve them?](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – hungrykoala Jun 28 '18 at 04:12

1 Answers1

1

You have a extra } at the end. the correct code would be

<?php 

$Servername="localhost";
$Username="root";
$Password="";
$dbname="db_unity";

$connection=new mysqli($Servername,$Username,$Password,$dbname);

if(!$connection){
    die("connection failed".mysqli_connect_error());

} else {
    echo "connected";
} 

?>

Also, be sure if you need that closing ?> tag. It's a good practice to not close the php tag unless it's required.

  • Thanks...It works! – Sajjad Jun 28 '18 at 04:25
  • Great!. If I answered your question, please mark it as such. –  Jun 28 '18 at 04:28
  • 1
    Should of voted to close typos.. This question was caused by a problem that can no longer be reproduced **or a simple typographical error**. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting.. or as a dupe of [PHP parse/syntax errors; and how to solve them.](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them/18092308#18092308) – Lawrence Cherone Jun 28 '18 at 06:33
  • @LawrenceCherone My duplicate flag for this was disputed. – hungrykoala Jun 28 '18 at 07:14