![](/img/trans.png)
[英]How to Show Profile Picture of User on Change password form (Picture of Logged In user should be show) in HTML/PHP
[英]PHP MySQLi How to show user profile image in html table?
我正在嘗試在 HTML 表中顯示用戶的個人資料圖片,我在其中列出了用戶的其余信息。 但是我無法顯示它,而是在表格中顯示了Broken Image 。 如果我右鍵單擊“損壞的圖像”並選擇“在新選項卡中打開圖像”我可以看到圖像的路徑和圖像父目錄的鏈接我正在將圖像的路徑上傳到數據庫和將圖像存儲到文件夾 ( images/profilepic )。
有人能幫助我嗎? 非常感謝!
這是我的 insert.php 代碼:
<?php
$server = "localhost";
$user = "root";
$pass = "";
$dbname = "employees";
// Create connection
$conn = mysqli_connect($server, $user, $pass, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$profile_file = basename($_FILES['profileimg']['name']);
$profile_path = "images/profilepic/$profile_file";
$profile_file = mysqli_real_escape_string($conn, $profile_file);
move_uploaded_file($_FILES['profileimg']['tmp_name'], $profile_path);
$sql = "INSERT INTO addemployees (profileimg)
VALUES ('$profile_file')";
if (mysqli_query($conn, $sql)) {
header("location: employees.php");
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
//Close the connection
mysqli_close($conn);
?>
這就是我展示它的地方:
<table id="dtBasicExample" class="table table-bordered table-hover text-center">
<thead>
<tr class="naslov">
<th class="th-sm">ID:</th>
<th class="th-sm">Profile Picture:</th>
<th class="th-sm">First Name:</th>
<th class="th-sm">Last Name:</th>
<th class="th-sm">DOB:</th>
<th class="th-sm">EMBG:</th>
<th class="th-sm">Work Position:</th>
<th class="th-sm">Address:</th>
<th class="th-sm">Contract:</th>
<th class="th-sm" colspan="2">Опции:</th>
</tr>
</thead>
<tbody id="myTable">
<?php
$conn = mysqli_connect("localhost", "root", "", "employees");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * from addemployees";
$result = $conn-> query($sql);
if ($result-> num_rows > 0) {
while ($row = $result-> fetch_assoc()) {
echo "<tr>
<td>".$row['id']."</td>
<td><img src='images/profilepic/'". $row['profileimg'] ."' border=0 class='tile' id='profileimg'></td>
<td>".$row['fname']."</td>
<td>".$row['lname']."</td>
<td>".$row['dob']."</td>
<td>".$row['embg']."</td>
<td>".$row['workposition']."</td>
<td>".$row['address']."</td>
</tr>";
}
echo "</table>";
}
else {
echo "0 results";
}
$conn-> close();
?>
</tbody>
刪除<img src
變量前的單引號:
<td><img src='images/profilepic/". $row['profileimg'] ."'
^-- remove the ' here ^-- but leave this one
你現在擁有它的方式,你的變量在src
屬性之外:
// if $row['profileimg'] is image.jpg:
<img src='images/profilepic/'". $row['profileimg'] ."' border=0>
// will become:
<img src='images/profilepic/'image.jpg' border=0>
// ^-- end of the src='' argument
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.