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");
?>
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");
?>
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).
You are missing a closing parenthesis at the end of
if(User::userNameExists($_GET['username'])
Do this instead
if(User::userNameExists($_GET['username']))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With