我面临两个问题,一个是我无法使用PDO将数据上传到数据库,即使代码是正确的(据我确定),另一个是我'当重新加载页面时,得到这样的警告很少警告说警告:session_start():无法发送会话缓存限制器 - 已发送的标头(输出从C:\ xampp \ htdocs \ Ecommerce \ header.php:111开始)在第3行的C:\ xampp \ htdocs \ Ecommerce \ Admin Panel.php 中,当我点击退出按钮时,警告显示警告:无法修改标题信息 - 已经发送的标题(输出开始于第37行的C:\ xampp \ htdocs \ Ecommerce \ Admin Panel.php中的C:\ xampp \ htdocs \ Ecommerce \ header.php:111)。以下是我的代码,如果我做错了什么,请帮帮我。
这是我的header.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>ECOM Site</title>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<link href="Styling.css" rel="stylesheet">
<link href="Sliders.css" rel="stylesheet">
<script type="application/x-javascript">
function showDiv() {
document.getElementById('sign-in').style.display = "block";
}
</script>
</head>
<body>
<div class="header1">
<div class="container">
<div class="header-top">
<div class="row">
<div class="col-sm-4">
<form class="navbar-form navbar-left">
<div class="input-group">
<input type="text" class="form-control search" placeholder="Search">
<span class="input-group-btn">
<!-- <button class="btn btn-default submit" type="button" ><i class="glyphicon glyphicon-search" style = "color : #e98fa0;"></i></button>-->
<a class="btn btn-default submit" role="button" ><i class="glyphicon glyphicon-search" style = "color : #e98fa0;"></i></a>
</span>
</div>
</form>
</div>
<div class="col-sm-4 logo text-center ">
<a href="index.php">LOGO</a>
</div>
<div class="col-sm-4 text-center">
<div class="login-bars">
<a class="btn btn-default log-bar" href="#" role="button" >Sign up</a>
<button type="submit" class="btn btn-default log-button" onclick = "showDiv()">Login</button>
<a class="btn btn-default log-bar" href="Productpage.php" role="button">Cart</a>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
<div class="header-botom">
<div class="content white">
<nav class="navbar navbar-default nav-menu" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<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.php">LOGO</a>
</div>
<div class="clearfix"></div>
<!--/.navbar-header-->
<div class="collapse navbar-collapse collapse-pdng " id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav nav-font">
<li><a href="#">Home</a></li>
<li><a href="#">Ear Rings</a></li>
<li><a href="#">Jewelry </a></li>
<li><a href="#">Accessories</a></li>
</ul>
<div class="clearfix"></div>
</div>
<!--/.navbar-collapse-->
<div class="clearfix"></div>
</nav>
<div class="clearfix"></div>
</div>
</div>
</div>
<div id ="sign-in" class=" container-fluid login " style="display: none;">
<div class="container">
<h3> Login </h3>
<br>
<form>
<div class="row">
<div class="col-md-3">
<div class="form-group ">
<!--<label for="username" class="head">Email or Phone</label>-->
<input type="text" class="form-control" id="username" Placeholder="email or Phone">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<!--<label for="password" class="head">Password</label>-->
<input type="password" class="form-control" id="Password"placeholder = "Password">
</div>
</div>
<div class="col-md-4">
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
<a href="#" >Forgot Password</a>
</div>
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-default pull-left">Submit</button>
<br>
</div>
</div>
</form>
</div>
</div>
<br>
</div>
这是我的Admin Panel.php代码
<?php
include('header.php');
session_start();
require ('includes/connect.php');
if (isset($_SESSION['logged_in'])) {
require ('includes/Product.php');
$product = new Product;
if(isset($_POST['productname'] , $_POST['oldprice'] , $_POST['newprice'] , $_POST['briefdescription'] , $_POST['productdescription'] , $_POST['productspecifications'])){
$productname = $_POST['productname'];
$oldprice = $_POST['oldprice'];
$newprice = $_POST['newprice'];
$briefdescription = $_POST['briefdescription'];
$productdescription = $_POST['productdescription'];
$productspecifications = $_POST['productspecifications'];
if(empty($productname) or empty ($oldprice) or empty ($newprice) or empty ($briefdescription) or empty ($productdescription) or empty ($productspecifications)){
$error = "All fields are required";
}
else{
$query = $pdo -> prepare("INSERT INTO products (product_name ,old_price , new_price , brief_description , product_description , product_specifications) VALUES (?,?,?,?,?,?)");
$query -> bindValue(1, $productname);
$query -> bindValue(2, $oldprice);
$query -> bindValue(3, $newprice);
$query -> bindValue(4, $briefdescription);
$query -> bindValue(5, $productdescription);
$query -> bindValue(6, $productspecifications);
$query ->execute();
header('location:index.php');
}
}
//Logout
function logout (){
session_destroy();
header('location:Admin Panel.php');
}
if(isset($_POST['logout'])) {
logout();
}
?>
<div class="container">
<div class="col-sm-6">
<form action = "Admin Panel.php" method="POST">
<button type="submit" class="btn btn-primary " name = "logout" >Logout</button>
</form>
<?php if(isset($error)){ ?>
<small style = "color : #aa0000"; ><?php echo $error ?></small>
<br><br>
<?php } ?>
<form>
<div class="form-group ">
<label for="productname" class="upload">Product name</label>
<input type="text" class="form-control" name="productname" id="productname">
</div>
<div class="form-group ">
<label for="oldprice" class="upload">Old price</label>
<input type="text" class="form-control" name="oldprice" id="oldprice">
</div>
<div class="form-group ">
<label for="newprice" class="upload">New price</label>
<input type="text" class="form-control" name="newprice" id="newprice">
</div>
<div class="form-group ">
<label for="briefdescription" class="upload">Brief description</label>
<textarea class="form-control" id="briefdescription" name=" briefdescription" rows="7"></textarea>
</div>
<div class="form-group ">
<label for="productdescription" class="upload">Description</label>
<textarea class="form-control" id="productdescription" name="productdescription" rows="7"></textarea>
</div>
<div class="form-group ">
<label for="productspecifications" class="upload">Specifications</label>
<textarea class="form-control" id="productspecifications" name="productspecifications" rows="7"></textarea>
</div>
<button type="submit" class="btn btn-default " >Submit</button>
</form>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
<?php
}
else {
include ('includes/connect.php');
include ('includes/product.php');
if(isset($_POST['username'] , $_POST['password']))
{
$username = $_POST['username'];
$password = md5($_POST['password']);
if(empty($username) or empty($password))
{
$error = "Please fill all the fields";
}
else
{
$query = $pdo->prepare("SELECT * FROM product_login WHERE username = ? AND password = ? ");
$query->bindValue ( 1, $username);
$query->bindValue ( 2, $password);
$query->execute();
$num=$query->rowCount();
if($num==1) {
$_SESSION['logged_in']= true;
header('location:Admin Panel.php');
exit();
}
else{
$error = "Please enter correct Username and Password";
}
}
}
?>
<div class="container">
<div class="row">
<div class="col-md-8">
<h3>Admin Login</h3>
<br>
<?php if(isset($error)){ ?>
<small style = "color : #aa0000"; ><?php echo $error ?></small>
<br><br>
<?php } ?>
<form action ="Admin Panel.php" method ="POST" class = "form-inline">
<div class="form-group">
<input class="form-control" name="username" type="text" id="Username" placeholder ="Username"/>
</div>
<div class="form-group text-left">
<input class="form-control" name = "password" type="password" id="password" Placeholder ="Password"/>
</div>
<button type="submit" class="btn btn-primary " >Submit</button>
</form>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
<?php
}
?>
这是我的Product.php包含文件。
<?php
class Product {
public function fetch_all() {
global $pdo;
$query = $pdo->prepare("SELECT * FROM products");
$query -> execute();
return $query->fetchAll();
}
}
?>
这是我的数据库Database Structure
的结构三江源
答案 0 :(得分:0)
遇到问题的人......我没有在表单中添加表单方法和操作。
<form action="Admin Panel.php method="POST">
<div class="form-group ">
<label for="productname" class="upload">Product name</label>
<input type="text" class="form-control" name="productname" id="productname">
</div>
<div class="form-group ">
<label for="oldprice" class="upload">Old price</label>
<input type="text" class="form-control" name="oldprice" id="oldprice">
</div>
<div class="form-group ">
<label for="newprice" class="upload">New price</label>
<input type="text" class="form-control" name="newprice" id="newprice">
</div>
<div class="form-group ">
<label for="briefdescription" class="upload">Brief description</label>
<textarea class="form-control" id="briefdescription" name=" briefdescription" rows="7"></textarea>
</div>
<div class="form-group ">
<label for="productdescription" class="upload">Description</label>
<textarea class="form-control" id="productdescription" name="productdescription" rows="7"></textarea>
</div>
<div class="form-group ">
<label for="productspecifications" class="upload">Specifications</label>
<textarea class="form-control" id="productspecifications" name="productspecifications" rows="7"></textarea>
</div>
<button type="submit" class="btn btn-default " >Submit</button>
</form>
无论如何,我的一个问题就解决了..谢谢伙计。