如何使用 $_GET 获取页面标题
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>
对不起,我不明白如何在 Whosebug 中解决这个难看的代码
您的行顺序不正确,在设置 $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 injection,请参阅:
How can I prevent SQL injection in PHP?
我刚刚制作了用户配置文件脚本的一部分,但我不知道如何在标题中显示用户名。请帮助这里是代码:
<?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>
对不起,我不明白如何在 Whosebug 中解决这个难看的代码
您的行顺序不正确,在设置 $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 injection,请参阅: How can I prevent SQL injection in PHP?