0
好吧,所以我想知道什麼是最好的方式來顯示用戶自己的照片,如果我的方式是安全的或我應該改變。最好的方式向用戶展示他們的照片
網址:
http://localhost/project/everyone/myphoto.php?num=2
PHP代碼:
$user_id = $_SESSION['user_id'];
if (isset($_GET['num'])) {
$num = $_GET['num'];
if ($stmt = $dbconn->prepare("SELECT 1 FROM t_photos WHERE id ='$num' AND user_id ='$user_id' LIMIT 1")) {
$stmt->execute();
$stmt->store_result();
$rows = $stmt->num_rows;
if ($rows === 1) {
$stmt = $dbconn->prepare("SELECT url,uploaddate FROM t_photos WHERE id = ?");
$stmt->bind_param('i', $num); // Bind "$email" to parameter.
$stmt->execute(); // Execute the prepared query.
$stmt->store_result();
$stmt->bind_result($photopath, $uploadtime); // get variables from result.
$stmt->fetch();
} else {
$error2 = "error 2 fuck";
require 'notfound.php';
die();
}
}
}
HTML & PHP代碼:
是的,我做到了這一點,以防萬一我得到一個錯誤,那我怎麼知道什麼部分搞亂 – ThinkkSo
你應該連接表而不是做2個查詢。 – vikingmaster
@Jari我會,但如果查詢1失敗它會導致其他而不是2查詢 – ThinkkSo