将php mysqli查询行结果回显到html div

时间:2019-02-09 00:17:15

标签: php mysqli

我试图将结果['first'']从表回显到特定的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>

1 个答案:

答案 0 :(得分:0)

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