首页 > 解决方案 > 提交表单提交后目标页面不显示

问题描述

我有一个员工表,但提交时表单数据在 SQL 数据库的员工表中更新,但未header('location:employeedata.php')显示员工数据页面 ( )。当我删除有时字段时,它可以完美地在员工数据页面上显示数据。下面是我的PHP代码。有人,请帮帮我

<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-state=1"/>
<link type="text/css" rel="stylesheet" href="css/bootstrap.css"/>
<script src ="js/jquery-3.4.1.min.js" ></script>
<script src ="js/bootstrap.js" ></script>
<link rel="stylesheet" href="stylemenu.css">
<style type="text/css">
body
{
    background-image:url(water.png);
    background-size:cover;
}
</style>
</head>
<body>
<?php
session_start();
include("samadonconnection.php");
error_reporting(0);
?>
<div class ="container">    
<div class="row">
<div class="col-sm-6"> <h2> Test </h2> </div>
<div class="col-sm-6"> 
<?php echo "<div style=\"float:right\"> Welcome ". $_SESSION['user']['username']."! </div>"; ?> </div>
</div>
 <div class="topnav">
<div class="col-sm-12">
<a href="home.php">HOME</a>
<a href="create_user.php"> + ADD USER</a>
<a class="active" href="employee.php" style="color:blue;">EMPLOYEE</a>
<a href="employeedata.php">EMPLOYEE DATA</a>
<a href="home.php?logout='1'" style="color: red;">LOG OUT</a>
<a href="cont.php">CONTACT US</a>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div id="ui"> 
<form action="" method="GET" class="form-group">
<div class="row">
<div class ="col-lg-3">
<label> Today Date :</label>
<input type ="date" name ="date" class ="form-control"  placeholder=".....">
</div>
<div class ="col-lg-3">
<label> Birth Date :</label>
<input type ="date" name ="birth" class ="form-control"  placeholder="......">
</div>
<div class ="col-lg-3">
<label> Mobile :</label>
<input type ="text" name ="mobile" class ="form-control"  placeholder="......">
</div>
<div class ="col-lg-3">
<label> Father Name :</label>
<input type ="text" name ="father" class ="form-control"  placeholder=".....">
</div>
</div>
<br>
<div class="row">
<div class ="col-lg-3">
<label> First Name :</label>
<input type ="text" name ="fname" class ="form-control"  placeholder=".....">
</div>
<div class ="col-lg-3">
<label> Last Name :</label>
<input type ="text" name ="lname" class ="form-control"  placeholder="......">
</div>
<div class ="col-lg-3">
<label> Gender :</label>
<select name="gender" class="form-control"> 
<option> Choose ... </option>
<option> Male </option>
<option> Female </option>
</select>
</div>
<div class ="col-lg-3">
<label> Marital :</label>
<select name="marital" class="form-control"> 
<option> Choose ... </option>
<option> Married </option>
<option> Unmarried </option>
</select>
</div>
</div>
<br>
<div class="row">
<div class ="col-lg-3">
<label> Email :</label>
<input type ="text" name ="email" class ="form-control"  placeholder="......">
</div>
<div class ="col-lg-3">
<label> Qualification :</label>
<input type ="text" name ="qualification" class ="form-control"  placeholder=".....">
</div>
<div class ="col-lg-6">
<label> Address :</label>
<input type ="text" name ="address" class ="form-control"  placeholder="......">
</div>
</div>
<br>
<div class="row">
<div class ="col-lg-3">
<label> Pin Code :</label>
<input type ="text" name ="pin" class ="form-control"  placeholder="......">
</div>
<div class ="col-lg-3">
<label> District :</label>
<input type ="text" name ="district" class ="form-control"  placeholder=".....">
</div>
<div class ="col-lg-3">
<label> State :</label>
<input type ="text" name ="state" class ="form-control"  placeholder="......">
</div>
<div class ="col-lg-3">
<label> Country :</label>
<input type ="text" name ="country" class ="form-control"  placeholder="......">
</div>
</div>
<br>
<div class="row">
</div>
<br>
<input type ="submit" name ="submit" value ="SUBMIT" class ="btn btn-primary btn-block btn-lg">
</form>
<?php
if($_GET['submit'])
{
$da = $_GET['date'];
$bi = $_GET['birth'];
$mo = $_GET['mobile'];
$fa = $_GET['father'];
$fn = $_GET['fname'];
$ln = $_GET['lname'];
$ge = $_GET['gender'];
$ma = $_GET['marital'];
$em = $_GET['email'];
$qu = $_GET['qualification'];
$ad = $_GET['address'];
$pi = $_GET['pin'];
$di = $_GET['district'];
$st = $_GET['state'];
$co = $_GET['country'];
if( $fn!="" && $ln!="") 
{
$query = "INSERT INTO employee VALUES 
( '$sl','$da','$bi','$mo','$fa','$fn','$ln','$ge','$ma','$em','$qu','$ad' ,'$pi','$di','$st','$co')";
$data = mysqli_query($conn,$query);
if($data)
{
header('location:employeedata.php');
}
}
else
{
echo "All fields are required";
}
}
?>
</div>
</div>
</div>
</div>  
</body>
</html>

标签: php

解决方案


将输出发送到浏览器后,您无法进行标头重定向,您将收到“标头已发送”错误。将您的表单处理代码移到 html 输出之前。


推荐阅读