如何使用$ _GET获取页面标题

时间:2015-11-08 13:56:08

标签: php mysql database user-profile page-title

我刚刚制作了一个userprofile脚本的一部分而且我不知道如何在标题中显示用户名。请帮助这里是代码:

    <?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中解决这个问题

1 个答案:

答案 0 :(得分:0)

您的行次数不正确,在设置$page_title之前指定$get

<?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?