Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么在php函数中获取storename数据_Php_Html_Function_Mysqli - Fatal编程技术网

为什么在php函数中获取storename数据

为什么在php函数中获取storename数据,php,html,function,mysqli,Php,Html,Function,Mysqli,这是一个脚本,用于在PHP中以echo的形式检索用户数据 <?php include "db_config.php"; class User{ public $db; public function __construct(){ $this->db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE); if(mysqli_connect_errno

这是一个脚本,用于在PHP中以
echo
的形式检索用户数据

<?php 
include "db_config.php";

class User{     
    public $db;
    public function __construct(){
        $this->db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);

        if(mysqli_connect_errno()) {     
            echo "Error: Could not connect to database."; 
           exit; 
        }
    }

    /*** for registration process ***/
    public function reg_user($ustore, $unik, $name,$username,$password,$email){

        $password = md5($password);
        $sql="SELECT * FROM users WHERE uname='$username' OR uemail='$email' OR unik='$unik'";

        //checking if the username or email is available in db
        $check =  $this->db->query($sql) ;
        $count_row = $check->num_rows;

        //if the username is not in db then insert to the table
        if ($count_row == 0){
            $sql1="INSERT INTO users SET ustore='$ustore', unik='$unik', uname='$username', upass='$password', fullname='$name', uemail='$email'";
            $result = mysqli_query($this->db,$sql1) or die(mysqli_connect_errno()."Data cannot inserted");
            return $result;
        }
        else { return false;}
    }

    /*** for login process ***/
    public function check_login($emailusername, $password){

        $password = md5($password);
        $sql2="SELECT uid from users WHERE uemail='$emailusername' or uname='$emailusername' or  unik='$emailusername' and upass='$password'";

        //checking if the username is available in the table
        $result = mysqli_query($this->db,$sql2);
        $user_data = mysqli_fetch_array($result);
        $count_row = $result->num_rows;

        if ($count_row == 1) {
            // this login var will use for the session thing
            $_SESSION['login'] = true; 
            $_SESSION['uid'] = $user_data['uid'];
            $_SESSION['ustore'] = $user_data['ustore'];
            return true;
        }
        else{
            return false;
        }
    }

    /*** for showing the username or fullname ***/
    public function get_fullname($uid){
        $sql3="SELECT fullname FROM users WHERE uid = $uid";
        $result = mysqli_query($this->db,$sql3);
        $user_data = mysqli_fetch_array($result);
        echo $user_data['fullname'];
    }

    /*** for showing the Store ID user ***/
    public function get_store($uid){
        $sql4="SELECT ustore FROM users WHERE uid = $uid";
        $result = mysqli_query($this->db,$sql4);
        $user_data = mysqli_fetch_array($result);
        echo $user_data['ustore'];
    }

    /*** for showing the NIK user ***/
    public function get_nik($uid){
        $sql5="SELECT unik FROM users WHERE uid = $uid";
        $result = mysqli_query($this->db,$sql5);
        $user_data = mysqli_fetch_array($result);
        echo $user_data['unik'];
    }

    /*** for showing the NAMA TOKO user ***/
    public function get_store_name($uid){
        $sql6="SELECT STORE_ID, STORE_NAME FROM users INNER JOIN store ON store.STORE_ID=users.ustore where uid = $uid ";
        $result = mysqli_query($this->db,$sql6);
        $user_data = mysqli_fetch_array($result);
        echo $user_data['STORE_NAME'];
    }

    /*** starting the session ***/
    public function get_session(){    
        return $_SESSION['login'];
    }

    public function user_logout() {
        $_SESSION['login'] = FALSE;
        session_destroy();
    }
}

class Store{

    public $db;
    public function __construct(){
        $this->db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);

        if(mysqli_connect_errno()) {     
            echo "Error: Could not connect to database.";    
            exit; 
        }
    }

    /*** for showing the username or fullname ***/
    public function get_store_info($ustore){
        $sql="SELECT * FROM data_exp INNER JOIN store ON store.STORE_ID=data_exp.STORE ";
        $result = mysqli_query($this->db,$sql);
        $user_data = mysqli_fetch_array($result);
        echo $result;
    }
}
试试这个

$user = new User;
$store_id = $user->get_store($uid);
print_r($store_id);

应该是
echo$store\u id??错误是怎么说的?我编辑过,你能再试一次吗?你把代码粘贴到哪里了?我假设$uid是已知的。