douou6696 2018-12-18 20:25
浏览 12

too long

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);
}     
?>
  • 写回答

1条回答 默认 最新

  • duanchi6397 2018-12-18 22:17
    关注

    i think u should write :

    $sql = "SELECT * FROM member WHERE email = '".$this->username."'";
    

    or :

    $sql = "SELECT * FROM member WHERE email = '{$this->username}'";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入