6

I just finished working on a site in PHP and decided to upload it unto my web server, but when I try to run pages with static method calls I get this error Unexpected T_PAAMAYIM_NEKUDOTAYIM. I know this has to do with double colon error, but I do not understand why it works on my local web server and refuses to work on my remote web server.

Due to this error, I had to through my whole site converting all static methods to instance methods

<?php
class User
{
    private $userId;

    public function __construct()
    {
        if(func_num_args() == 1)
        {
            $this->userId   =   func_get_arg(1);
        }
    }

    public static function userNameExists($name)
    {
        global $dbc;

        if(gettype($name) != "string")
        {
            die("Invalid Function Parameter");
        }

        $sql    =   "SELECT username FROM users WHERE users.username='$name'";
        $result =   mysqli_query($dbc, $sql) or die("Could Not Check Username at This Time: ".mysqli_error($dbc));

        if(mysqli_num_rows($result) > 0)
        {
            return true;
        }
        else
        {

            return false;
        }
    }
?>

When I call it:

<?php
   require("users.php");

   if(User::userNameExists($_GET['username']))
     header("Location:index.php");
?>
George
  • 3,757
  • 9
  • 51
  • 86

4 Answers4

3

You are missing a } in the end of your code,

<?php
class User
{
    private $userId;

    public function __construct()
    {
        if(func_num_args() == 1)
        {
            $this->userId   =   func_get_arg(1);
        }
    }

    public static function userNameExists($name)
    {
        global $dbc;

        if(gettype($name) != "string")
        {
            die("Invalid Function Parameter");
        }
        //Think about escaping user input
        $name = mysqli_real_escape_string($name);
        $sql    =   "SELECT username FROM users WHERE users.username='$name'";
        $result =   mysqli_query($dbc, $sql) or die("Could Not Check Username at This Time: ".mysqli_error($dbc));

        if(mysqli_num_rows($result) > 0)
        {
            return true;
        }
        else
        {

            return false;
        }
    }
}//This one
?>

You're also missing " in your require statement,

<?php
   require("users.php");//This one

   if(User::userNameExists($_GET['username']))
     header("Location:index.php");
?>
ilyes kooli
  • 11,959
  • 14
  • 50
  • 79
2

If the exact same code is working locally, but gives a syntax error on a live server, you might be using different PHP versions (an old PHP4 version on the server, perhaps).

Joel L
  • 3,031
  • 1
  • 20
  • 33
1

You are missing a closing parenthesis at the end of

if(User::userNameExists($_GET['username'])

Do this instead

if(User::userNameExists($_GET['username']))

1

Try to check the PHP version of your web server and local machine. You can refer to this link. You might have same problem and solution.

Community
  • 1
  • 1
Stuart
  • 711
  • 1
  • 11
  • 35