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?!!!!!

3
  • 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 :) Jun 28, 2018 at 4:08
  • there is extra '}' at the end of file before end of PHP tag '?>'
    – Jaydp
    Jun 28, 2018 at 4:08
  • 1
    Possible duplicate of PHP parse/syntax errors; and how to solve them? Jun 28, 2018 at 4:12

1 Answer 1

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.

4
  • Thanks...It works!
    – Sajjad
    Jun 28, 2018 at 4:25
  • Great!. If I answered your question, please mark it as such.
    – user9886608
    Jun 28, 2018 at 4: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. Jun 28, 2018 at 6:33
  • @LawrenceCherone My duplicate flag for this was disputed. Jun 28, 2018 at 7:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.