php - 将 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>
解决方案
就这样做
<?= $row['firstname']; ?>
推荐阅读
- halide - 使用 AutoScheduler 和 GPU 调度时卤化物索引错误,但不是默认 CPU 调度
- python - 禁用某些类、Visual Studio Code、Python 的自动完成功能
- terraform - 如何在没有交互式提示的情况下执行 Terraform 操作?
- telerik - “itemSwipeProgressEnded”在 android 上总是返回 '0'
- database - neo4j 图找到从父母到每个孩子的所有路径,没有关系
- javascript - 相当于 HTML/Javascript 页面中 curl 的“解决”选项
- bash - Bash IFS 忽略行尾的分隔符
- node.js - history.push 在单击按钮之前无法等待或同步
- r - 如何在组中为基因着色并在 ggplot2 中的箭头上方有基因标签?
- python - print a list in a square pattern [python]