我已經瀏覽過所以獲得我的代碼的幫助,但沒有遇到/瞭解代碼,這有助於我的錯誤。在PHP中顯示名字問題
我有一個包含用戶名,密碼和名字的表的數據庫。 我想在登錄儀表板時顯示用戶的名字。
我收到此錯誤的代碼,我將在下面提供:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/sites/s/ssangar.com/public_html/PMWebsite/dashboard.php:31) in /var/sites/s/ssangar.com/public_html/PMWebsite/dashboard.php on line 31
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /var/sites/s/ssangar.com/public_html/PMWebsite/dashboard.php on line 35
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /var/sites/s/ssangar.com/public_html/PMWebsite/dashboard.php on line 36
我的日誌代碼在:
<?php
session_start();
if(isset($_POST['submitted']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$connect = mysqli_connect("", "", "", "");
if (mysqli_connect_errno()){
echo mysqli_connect_error();
}
$query = "SELECT * FROM members where username = '$username'";
$result = mysqli_query($connect, $query);
$log = mysqli_fetch_array($result);
$dbusername=$log['username'];
$dbpassword=$log['password'];
// }
if($username == $dbusername && $password == $dbpassword)
{
$_SESSION['username'] = $dbusername;
$_SESSION['password'] = $dbpassword;
header("Location: PMWebsite/dashboard.php");
}else
{
echo "Username or Password Incorrect";
}
}else{
echo "No Connection";
}
?>
代碼儀表盤顯示的用戶名:
<?php ob_start();
session_start(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Dashboard</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="dashboard.css" rel="stylesheet">
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
</head>
<body>
<?php
$user = $_SESSION['username'];
$query = "SELECT firstName FROM members where username = '$username'";
$result = mysqli_query($connect, $query);
$log = mysqli_fetch_array($result);
$dbfirstName=$log['firstName'];
print_r($log);
echo $query; ?>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">Aston Racing: Formula Student</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Settings</a></li>
<li><a href="#">Profile</a></li>
<li><a href="#">Log Out</a></li>
</ul>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li class="active"><a href="#"><img src="PM/projects.png"> Projects</a></li>
<li><a href="gantt/teamGantt.html"><img src="PM/teamtimetable.png"> Team Gantt</a></li>
<li><a href="#"><img src="PM/meetings.png"> Meetings</a></li>
<li><a href="parts.html"><img src="PM/parts.png"> Part Orders</a></li>
<li><a href="#"><img src="PM/fileshare.png"> File Share</a></li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 class="page-header">Welcome <?php echo $dbfirstName; ?>!</h1>
<div class="row placeholders">
<div class="col-xs-6 col-sm-3 placeholder">
<h4>Tasks To Do</h4>
<span class="text-muted"></span>
</div>
<div class="col-xs-6 col-sm-3 placeholder">
<h4>Upcoming deadlines</h4>
<span class="text-muted"></span>
</div>
<div class="col-xs-6 col-sm-3 placeholder">
<h4>Goals</h4>
<span class="text-muted"></span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="docs.min.js"></script>
</body>
</html>
任何幫助將非常感謝謝謝!
刪除這個'$ dbusername = $ log ['username'];'你沒有選擇它,因此打破了代碼! –
<?php session_start();這應該是最前面的身體標籤... –
你可以嘗試這樣的事情是這樣的$查詢$查詢=「選擇*從成員,其中用戶名='」。$ username。「'」; – JamesMarc