I wrote a class for get some information about my client from database (MySQL). as we can see below :
<?php
class Player {
public $username;
public $inf;
public function __construct ($username, $inf){
$this->username = $username;
$this->inf = $inf;
}
public function getInfuser (){
include('connectdatabase.php');
$sql = "SELECT * FROM member WHERE email = '.$this->username.'";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
switch ($this->inf){
case ('email'):
$result = $row["email"];
break;
case ('playerid'):
$result = $row["playerid"];
break;
case ('inviteid'):
$result = $row["inviteid"];
break;
case ('hash'):
$result = $row["hash"];
break;
default:
$result = "Error";
break;
}
return $result;
}
}
?>
in the connectdatabase.php
page i wrote a connection to connect to my database i tested its work correctly.
and the page that i want to print information from my classes is here :
<?php
include ('classtest.php');
$username = 'chance';
$inf = 'inviteid';
$keyvan = new Player($username, $inf);
echo $keyvan->getInfuser ();
?>
i fixed some syntax error that were there.
[18-Dec-2018 20:14:52 UTC] PHP Parse error: syntax error, unexpected 'function__construct' (T_STRING), expecting variable (T_VARIABLE) in /home/jokerpoker021/public_html/classtest.php on line 8
[18-Dec-2018 20:14:52 UTC] PHP Parse error: syntax error, unexpected 'function__construct' (T_STRING), expecting variable (T_VARIABLE) in /home/jokerpoker021/public_html/classtest.php on line 8
[18-Dec-2018 20:14:53 UTC] PHP Parse error: syntax error, unexpected 'function__construct' (T_STRING), expecting variable (T_VARIABLE) in /home/jokerpoker021/public_html/classtest.php on line 8
[18-Dec-2018 20:16:34 UTC] PHP Fatal error: Call to a member function query() on null in /home/jokerpoker021/public_html/classtest.php on line 17
[18-Dec-2018 20:16:35 UTC] PHP Fatal error: Call to a member function query() on null in /home/jokerpoker021/public_html/classtest.php on line 17
now without any error but my information doesnt print and just show a white page and i dont know why. whats the problem with my codes ?
UPDATE : my connecttodatabase.php
file :
<?php
$servenm = "localhost";
$usnme = "username";
$passnm = "********";
$dbname = "jokerpok";
// Create connection
$conn = new mysqli($servenm, $usnme, $passnm, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>