首页 > 解决方案 > 将 php mysqli 查询行结果回显到 html div

问题描述

我正在尝试将结果 ['firstname'] 从表回显/显示到特定的 html div。查询本身正在运行,它会产生与登录的电子邮件相对应的正确名称 ($_SESSION) -

错误:

语法错误,意外的 T_ECHO

有人可以帮助我,以便我可以回显/显示此查询的结果并将它们显示在我喜欢的 html 代码中的任何位置。

<?php
session_start();
if(!isset($_SESSION["email"])){
header("Location: login.php");
exit(); }

$connection = mysqli_connect("********", "********", 
"********", "********");
if (!$connection) {
    die("Database connection failed: " . mysqli_connect_error());
}


//create query
$query = "SELECT * FROM usertable where email = '". $_SESSION['email'] ."'";

$result = mysqli_query($connection, $query);
$row = mysqli_fetch_array($result);

?>

<html> 
<head>
<title>
    </title>
</head>
<body>
<div id="userbox" class="userbox">
                    <a href="#" data-toggle="dropdown">

                        <div class="profile-info">
                            <span class="name">**<?php "echo . 
$row['firstname']" ?>**</span>
                            <span class="email"> "          "</span>
                        </div></a></div>
</body>

标签: phpmysqli

解决方案


就这样做 <?= $row['firstname']; ?>


推荐阅读