我面临的困境是我创建的用于存储varibale(用户名)的会话未显示。我想在用户注册<ul class="slider">
<li>
<img src="http://placehold.it/300/0074D9/FFFFFF?text=One"><span class="tip">Tip1</span></img>
</li>
<li>
<img src="http://placehold.it/300/39CCCC/000000?text=Two"><span class="tip">Tip2</span></img>
</li>
<li>
<img src="http://placehold.it/300/2ECC40/000000?text=Three"><span class="tip">Tip3 </span></img>
</li>
<li>
<img src="http://placehold.it/300/FF851B/000000?text=Four"><span class="tip">Tip4</span></img>
</li>
<li>
<img src="http://placehold.it/300/85144b/FFFFFF?text=Five"><span class="tip">Tip5</span></img>
</li>
</ul>
后在maindash.html
中显示用户名。
maindash.html代码:
index.php
index.php代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
MY SITE PLANNER | DASHBOARD
</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"\>
<link href="custom.css" rel="stylesheet" type="text/css" />
</head>
<body class="formbg">
<div class="container-fluid pi">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-6">
<p class="ppp">
<img src="image/my-site-planner-logo.png" class="ppp" />
</p>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<p class="up">
<!-- Hi, <a href="#">user</a> -->
<a href="#">Hello, <?php echo $_SESSION["name"]; ?></a>
<a href="#">settings</a>
<a href="#">logout</a>
</p>
<p id="dt">
System:
</p>
</div>
</div>
</div>
<div class="container-fluid fill">
<div class="row">
<div class="col-md-12 col col-sm-12 col-xs-12">
<div class="navbar">
<ul class="nalink">
<li>
<a href="trans.html">ViewIncomeStatement</a>
</li>
<li>
<a href="siteform.html">View/AddSite</a>
</li>
<li>
<a href="vendor.html">View/AddVendor</a>
</li>
<li>
<a href="item.html">View/AddItem</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-12">
<h3 class="side">
Summary of your site
</h3>
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<button class="btn btn-success view" name="submit" type="submit" >
View Income Statement
</button>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="table-responsive line">
<table class="table table-bordered dem">
<thead>
<tr class="hd">
<th width="3">Sr.</th>
<th width="6">Site Name</th>
<th width="6">Incomes</th>
<th width="6">Expenses</th>
<th width="6">Payables</th>
<th width="6">Balance</th>
<th width="10">Last Week Details</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><a href="#">SITE A</a> </td>
<td><a href="#">200000</a></td>
<td><a href="#">110000</a></td>
<td><a href="#">36000</a></td>
<td><a href="#">79000</a></td>
<td>Completed kitchen tiles work</td>
</tr>
<tr>
<td>2</td>
<td><a href="#">SITE B</a></td>
<td><a href="#">500000</a></td>
<td><a href="#">425000</a></td>
<td><a href="#">88000</a></td>
<td><a href="#">-13000</a></td>
<td>completed kitchen tiles work</td>
</tr>
<tr>
<td></td>
<td>TOTAL</td>
<td>700000</td>
<td>555000</td>
<td>124000</td>
<td>66000</td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-sm-6 col-xm-12">
<h3 class="side">
Your to do list
</h3>
</div>
<div class="col-md-6 col-sm-6 col-xm-12">
<button class="btn btn-success view" name="submit" type="submit">
Add Item
</button>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-12 col-sm-12 col-xm-12">
<div class="table-responsive line">
<table class="table table-bordered dem">
<thead>
<tr class="hd">
<th width="3">Sr.</th>
<th width="15">Task</th>
<th width="15">Site</th>
<th width="15">Added</th>
<th width="20">Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Need to co-ordinate with shahid bhai for comment bags</td>
<td>Site A</td>
<td>23-02-2016</td>
<td>
<a href="#">Delete Task</a> <a href="#">Mark as complete</a>
</td>
</tr>
<tr>
<td>2</td>
<td>Get registrations done</td>
<td>Site B</td>
<td>23-02-2016</td>
<td><a href="#">Delete Task</a> <a href="#">Mark as complete</a></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-sm-6 col-xm-12">
<h3 class="side">
Quick Navigation
</h3>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-12 col-sm-12 col-xm-12">
<div class="table-responsive line">
<table class="table table-bordered dem">
<tr class="hd">
<th>
<span>Select Site</span>
<select name="site" class="hig">
<option value="" selected="selected">Fetch site list</option>
<option value="site A">site A</option>
<option value="site B">site B</option>
</select>
<span class="dis">Select Operations</span>
<select name="site" class="hig">
<option value="" selected="selected">select your option</option>
<option value="option 1">View Site-wise imcome statement</option>
<option value="option 2">View Site-wise vendors</option>
<option value="option 3">View Site-wise items list</option>
<option value="option 4">List of Vendors Vs Expenses</option>
<option value="option 5">List of Item Vs Expenses</option>
<option value="option 6">List of Labours Vs Expenses</option>
<option value="option 7">List of Service Vs Expenses</option>
<option value="option 8">Payables List</option>
<option value="option 9">To-do List</option>
<option value="option 10">Work Done List</option>
</select>
<button class="btn btn-success viewl" name="submit" type="submit" >GO</button>
</th>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-sm-6 col-xm-12">
<h3 class="side">
Reporting Definations
</h3>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-12 col-sm-12 col-xm-12">
<div class="table-responsive line">
<table class="table table-bordered dem">
<tbody>
<tr class="info">
<td>View Site-wise imcome statement</td>
<td>Show Income Statement of a particular site</td>
</tr>
<tr>
<td>View Site-wise vendors</td>
<td>Show all the vandors of a perticular site</td>
</tr>
<tr class="info">
<td>View Site-wise items list</td>
<td>Show all the Items registerd in a particular</td>
</tr>
<tr>
<td>List of Vendors Vs Expenses</td>
<td>List of all vandors registerd in a perticular site vs amount paid to them</td>
</tr>
<tr class="info">
<td>List of Item Vs Expenses</td>
<td>List of all the Items used/registerd in a perticular site and the amount utilized on them</td>
</tr>
<tr>
<td>List of Labours Vs Expenses</td>
<td>List of the labours used in a perticular site and the amount paid to them</td>
</tr>
<tr class="info">
<td>List of Service Vs Expenses</td>
<td>List of the Service used in a perticular site and the amount paid to them</td>
</tr>
<tr>
<td>Payables List</td>
<td>List of Payables in perticula site</td>
</tr>
<tr class="info">
<td>To-do List</td>
<td>To-do List of a perticular site</td>
</tr>
<tr>
<td>Work Done List</td>
<td>List of Works Done on a perticular site</td>
</tr>
<tr class="info">
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
document.getElementById("dt").innerHTML = Date();
</script>
<script src="https://code.jquery.com/jquery-2.2.0.js"></script>
</body>
</html>
用户登录后,它不会显示用户名。我想创建它,因为用户名应该从数据库文件中获取并显示在<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "index";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "INSERT INTO form ( email, password )
VALUES ( '$email', '$password')";
if ($conn->query($sql) === TRUE) {
header('Location: sign-up.html');
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
if($count == 1)
{
$_SESSION['logged'] = true;
$_SESSION['username'] = $myusername;
echo "Login worked";
exit();
}
else
{
$_SESSION['logged']=false;
echo "Login failed";
exit();
}
?>
<li class='active' style='float:right;'>
<?php
if($_SESSION['logged'] == true)
{
echo $_SESSION["name"];
echo '<a href="logout.php"><span>Logout</span></a></li>';
}
elseif($_SESSION['logged'] == false)
{
echo '<a href="sign-up.html"><span>Login/Register</span></a></li>';
}
//Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM form where email = $email and password = $password";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo " Name: " . $row["name"]. ".<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
中。但它只显示我在代码中写的Hello。
答案 0 :(得分:0)
将您的maindash.html
页面重命名为.php
分机。在页面顶部(maindash.php
ie)确保你输入
<?php
session_start();
?>