[英]how to get page title using $_GET
我剛剛制作了用戶配置文件腳本的一部分,但我不知道如何在標題中顯示用戶名。 請幫助這里是代碼:
<?php
require_once('sp/conn.php');
$page_title = $get;
require_once('sp/head.php');
require_once('sp/userbar.php');
$get = $_GET['name'];
$query = "SELECT id,username from user_info where username = '$get'";
$data = mysqli_query($dbc, $query);
if (mysqli_num_rows($data) == 1) {
// The user row was found so display the user data
$row = mysqli_fetch_array($data);
$img_id = $row['id'];
?>
<body>
<div id="main">
<div id="user_lvl_avatar_bar">
<img src="img/ava/<?php echo $row['id'];?>" class="ava" /><font id="username"><?php echo $row['username']; ?></font>
</div><br />
<span id="left_user_notif_bar">
</span>
<span id="right_user_notif_bar">
</span>
<?php
} else {
$error_msg = "<div id=\"main\"><div id=\"red_field\">ERROR : Username doesn't exists.</div></div>";
echo $error_msg;
}
?>
</div>
</body>
</html>
抱歉,我不明白如何在 Stackoverflow 中修復這個丑陋的代碼
您的行順序不正確,在設置$get
之前分配$page_title
。
<?php
require_once('sp/conn.php');
require_once('sp/head.php');
require_once('sp/userbar.php');
$get = $_GET['name'];
$page_title = $get;
請注意,您的代碼容易受到SQL 注入,請參閱: 如何防止 PHP 中的 SQL 注入?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.