目前我有一个基本登录的网站,我只是想知道如何显示登录的唯一用户的名称,技能和描述。这是我到目前为止所做的。我只能找到有关如何将数据显示到表中的文章。这是更新后的代码:
<?php
include('session.php');
require 'config.php';
$sql = "SELECT * FROM profile";
$result = $conn->query($sql);
//echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="profile.css">
</head>
<body>
<ul>
<li><a href="welcome.php">Home</a></li>
<li><a href="postjob2.php">PostJob</a></li>
<li><a href="findjob.php">Find Job</a></li>
<li><a href="hiw2.php">How It Works</a></li>
<li><a href="notification.php">Notifications</a></li>
<li><a href="message.php">Message</a></li>
<li><a href="profile.php">profile</a></li>
</ul>
<h1>Welcome To Bid4MyJob</h1>
<li><a href="editprofile.php">edit profile</a></li>
<div id="ProfilePage">
<div id="LeftCol">
<div id="Photo"></div>
<div id="ProfileOptions">
a
</div>
</div>
<div id="Info">
<p>
<strong>Name:<?php echo $row["name"]?></strong>
<!--<span>James</span>-->
</p>
<p>
<strong>Skill:<?php echo $row["skill"]?><</strong>
<!--span>James</span>-->
</p>
<!-- <p>
<strong>review:<?php /*echo $row["review"]*/?><</strong>
<span>james</span>
</p> -->
<p>
<strong>Description:<?php echo $row["description"]?><</strong>
<span>James</span>
</p>
<!--<p>
<strong>Name:</strong>
<span>james</span>
</p>-->
</div>
<!-- Needed because other elements inside ProfilePage have floats
<div style="clear:both"></div>-->
</div>
</body>
</html>
答案 0 :(得分:1)
当用户成功登录时,创建一个cookie并存储他们的用户名或电子邮件,无论您在该cookie中使用了什么。您必须在login.php文件中执行此操作,以检查用户名和密码。
if(login success)
{
setCookie("username",value of username that you got from
user,'time()+3600','/');
echo "login successful";
}
之后在Profile中你有这样的代码;
<?php
$name=$_COOKIE['username'];
$sql=$conn->prepare("SELECT * from profile where username=?");
$stmt->bind_param('s', $name); // 's' specifies the variable type =>'string'
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
// do something with $row
}
?>
之后,您可以在div中显示信息,例如$ row [&#39;用户名&#39;]等。
答案 1 :(得分:0)
如果$ row []来自sql请求,只需在您的请求中添加如下内容:
$user = (...) your current user logged
(...)
select (...) where user = $user
答案 2 :(得分:0)
您可以使用 <?php
session_start(); //before anything else
include('session.php');
require 'config.php';
$sql = "SELECT * FROM profile";
$result = $conn->query($sql);
//assuming $row contains the information from
$_SESSION["user"] = $row;
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="profile.css">
</head>
....
....
在登录后识别人员并存储有关此人的信息。会话变量跨多个页面保存特定用户的数据。
会话ID存储在用户浏览器中,用于标识人员的<?php
session_start();
if(isset($_SESSION["user"]) {
//logged in
$name = $_SESSION["user"]["name"];
} else {
//not logged in
}
?>
<html>
....
....
数据。
在您的程序中,您可以轻松地执行以下操作:
USER_PARALLEL_EXECUTE_TASKS
现在在另一页上,您可以轻松地:
DBA_PARALLEL_EXECUTE_TASKS