2016-09-22 8 views
-1

PHPのechoの形式でユーザーデータを取得するスクリプトです。php関数のstorenameデータを取得する理由

<?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_data['ustore'])を作成しますか。関数(<? php $store_id = $user->get_store ($uid); echo $ store_id;?>)を呼び出すと、表示されません。誰でも助けてくれますか?

私はPHPの初心者です。

ユーザーから機能要求データを作成する方法を教えてください。

+0

を試してみてください;' ??そしてエラーは何と言うのですか? –

答えて

-1

はそれが$ STORE_IDエコー `でなければなりません。この

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

が動作していない、これは表示されません:( –

+0

ive編集しました。もう一度やり直してください。このコードをどこに貼り付けましたか?また、$ uidがわかっていると仮定しています。 –

関連する問題