我在mysql phhmyadmin中創建了兩個表。 1)reg_users 2)cam_details reg_users表需要電子郵件並傳遞一些唯一的ID也。 cam_details表需要相機相關的信息也有一個唯一的user_id。 但問題是當用戶登錄到我想要顯示用戶以前上傳的cam_details信息的網站。 但我無法做到這一點。 我是新來的PHP。登錄到網站後,有沒有辦法顯示cam_info?如何在使用php pdo mysql登錄網站時將所有用戶信息的用戶配置文件進行dsiplay?
我也使用過會話。
這是class.user.php文件 -
<?php
require_once 'dbconfig.php';
class USER
{
private $conn;
public function __construct()
{
$database = new Database();
$db = $database->dbConnection();
$this->conn = $db;
}
public function runQuery($sql)
{
$stmt = $this->conn->prepare($sql);
return $stmt;
}
public function lasdID()
{
$stmt = $this->conn->lastInsertId();
return $stmt;
}
public function register($email,$upass,$code)
{
try
{
$password = md5($upass);
$stmt = $this->conn->prepare("INSERT INTO reg_users(userEmail,userPass,tokenCode)
VALUES(:user_mail, :user_pass, :active_code)");
$stmt->bindparam(":user_mail",$email);
$stmt->bindparam(":user_pass",$password);
$stmt->bindparam(":active_code",$code);
$stmt->execute();
return $stmt;
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
public function login($email,$upass)
{
try
{
$stmt = $this->conn->prepare("SELECT * FROM reg_users WHERE userEmail=:email_id");
$stmt->execute(array(":email_id"=>$email));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() == 1)
{
if($userRow['userStatus']=="Y")
{
if($userRow['userPass']==md5($upass))
{
$_SESSION['userSession'] = $userRow['userID'];
return true;
}
else
{
header("Location: index.php?error");
exit;
}
}
else
{
header("Location: index.php?inactive");
exit;
}
}
else
{
header("Location: index.php?error");
exit;
}
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
public function is_logged_in()
{
if(isset($_SESSION['userSession']))
{
return true;
}
}
public function redirect($url)
{
header("Location: $url");
}
public function view_item($id){
try{
$stmt = $this->conn->prepare('SELECT user_id, user_name, mobile, cam_name, rent, model, cam_img, upd_date FROM cam_details WHERE user_id = :id');
$stmt->bindParam(':id', $id);
$stmt->execute();
return $stmt;
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
public function final_view()
{
try
{
$stmt = $this->conn->prepare('SELECT user_id, user_name, mobile, cam_name, rent, model, cam_img, upd_date FROM cam_details WHERE user_id= :id');
$stmt->bindParam(':id', $id);
$stmt->execute();
return $stmt;
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
public function getDetails()
{
try
{
$stmt = $this->conn->prepare('SELECT user_id, user_name, mobile, cam_name, rent, model, cam_img, upd_date FROM cam_details ORDER BY user_id DESC');
$stmt->execute();
return $stmt;
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
public function logout()
{
session_destroy();
$_SESSION['userSession'] = false;
}
}
<?php
class Database
{
private $host = "localhost";
private $db_name = "dslr_proj";
private $username = "root";
private $password = "";
public $conn;
public function dbConnection()
{
$this->conn = null;
try
{
$this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $exception)
{
echo "Connection error: " . $exception->getMessage();
}
return $this->conn;
}
}
?>
你可以顯示你目前有什麼代碼? –
你想爲用戶顯示什麼確切的行? –
我想顯示該特定用戶以前上傳的數據。 –