警告:无法修改标头信息 - 已在C:\ wamp64 \ www \ FSE \ admin \中发送的标头(输出从C:\ wamp64 \ www \ FSE \ template \ navigation.php:15开始)第71行的reg1.php 这是我得到的警告。两天后它很好,在其他电脑上运行良好。
以下是reg1.php的代码
<?php
#start session
session_start();
#database connection
include('../config/connection.php');
include('../config/setup.php');
if (!isset($_SESSION['user_name'])) {
header('location:login.php');
}
?>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo 'Registration | '.$site_title; ?></title>
<?php include('../config/css.php'); ?>
<?php include('../config/js.php'); ?>
</head>
<body>
<?php include('../template/navigation.php'); ?>
<h2> <center><strong>General Information </strong></center></h2>
<div id="wrap">
<div class="container">
<?php
if (isset($_POST['submitted'])==1) {
$name = mysqli_real_escape_string($dbc, $_POST['name']);
$fname = mysqli_real_escape_string($dbc, $_POST['fathername']);
$postadd = mysqli_real_escape_string($dbc, $_POST['postadd']);
$personaladd= mysqli_real_escape_string($dbc, $_POST['personaladd']);
$sex = mysqli_real_escape_string($dbc, $_POST['sex']);
$clients = mysqli_real_escape_string($dbc, $_POST['clients']);
$state = mysqli_real_escape_string($dbc, $_POST['state']);
$city = mysqli_real_escape_string($dbc, $_POST['city']);
$pincode = mysqli_real_escape_string($dbc, $_POST['pincode']);
$email = mysqli_real_escape_string($dbc, $_POST['email']);
$date = mysqli_real_escape_string($dbc, $_POST['date']);
$mobile = mysqli_real_escape_string($dbc, $_POST['mobile']);
$q = "INSERT INTO registration (name, fname, postadd, personaladd, sex, clients, state, city, pincode, email, dob, mobile) VALUES ('$name', '$fname', '$postadd', '$personaladd', '$sex', '$clients', '$state', '$city', '$pincode', '$email', '$date', '$mobile')" ;
$r = mysqli_query($dbc, $q);
if($_POST['clients']=="farmer")
{
$b = "insert into message values((SELECT reg_id FROM registration ORDER BY reg_id DESC LIMIT 1),(select mobile from registration where reg_id ORDER BY reg_id DESC LIMIT 1),(select Company from seed_testing where State=(select State from registration ORDER BY reg_id DESC LIMIT 1)));";
$c = mysqli_query($dbc, $b);
}
if ($r) {
$value_to_page = array(
"farmer" => 'farm.php',
"investor" => 'interest.php',
);
if(isset($_POST['submitted'])){
// process other fields like $_POST['some-other']
if(isset($_POST['clients']) && isset($value_to_page[$_POST['clients']])){
**#line71 error** header('Location: '.$value_to_page[$_POST['clients']]);
return;
}
}
} else {
echo 'please enter some data or error :'.mysqli_error($dbc);
echo '<p>'.$q.'</p>';
}
}
?>
<div class="col-md-6 col-md-offset-3">
<form action="reg1.php" method="post" >
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="First name and Surname" required>
</div>
<div class="form-group">
<label for="fathername">Father Name</label>
<input type="text" class="form-control" id="fathername" name="fathername" placeholder="fathername">
</div>
<div class="form-group">
<label for="postadd">Postal Address</label>
<textarea type="text" class="form-control" id="postadd" name="postadd" placeholder="postal Address"></textarea>
</div>
<div class="form-group">
<label for="personaladd">Personal Address</label>
<textarea class="form-control" id="personaladd" rows="5" name="personaladd" placeholder="personal address"></textarea>
</div>
<div class="form-group">
<label class="radio-inline">
<input type="radio" name="sex" id="male" value="Male"> Male
</label>
<label class="radio-inline">
<input type="radio" name="sex" id="female" value="Female"> Female
</label>
</div>
<?php
?>
<div class="form-group">
<label class="radio-inline">
<input type="radio" name="clients" id="farmer" value="farmer"> farmer
</label>
<label class="radio-inline">
<input type="radio" name="clients" id="investor" value="investor"> investor
</label>
</div>
<div class="form group">
<label>state</label>
<select class="form-control" name="state">
<option selected="" ></option>
<option value="Andra Pradesh">Andra Pradesh</option>
<option value="Arunachal Pradesh">Arunachal Pradesh</option>
<option value="Assam">Assam</option>
<option value="Bihar">Bihar</option>
<option value="Chhattisgarh">Chhattisgarh</option>
<option value="Delhi">Delhi</option>
<option value="Goa">Goa</option>
<option value="Gujarat">Gujarat</option>
<option value="Haryana">Haryana</option>
<option value="Himachal Pradesh">Himachal Pradesh</option>
<option value="Jammu and Kashmir">Jammu and Kashmir</option>
<option value="Jharkhand">Jharkhand</option>
<option value="Karnataka">Karnataka</option>
<option value="Kerala">Kerala</option>
<option value="Madya Pradesh">Madya Pradesh</option>
<option value="maharashtra">Maharashtra</option>
<option value="Manipur">Manipur</option>
<option value="Meghalaya">Meghalaya</option>
<option value="Mizoram">Mizoram</option>
<option value="Nagaland">Nagaland</option>
<option value="Orissa">Orissa</option>
<option value="Punjab">Punjab</option>
<option value="Rajasthan">Rajasthan</option>
<option value="Sikkim">Sikkim</option>
<option value="Tamil Nadu">Tamil Nadu</option>
<option value="Tripura">Tripura</option>
<option value="Uttaranchal">Uttaranchal</option>
<option value="Uttar Pradesh">Uttar Pradesh</option>
<option value="West Bengal">West Bengal</option>
</select>
</div>
<div class="form-group">
<label for="name">City</label>
<input type="text" class="form-control" id="city" name="city" placeholder="Enter your city">
</div>
<div class="form-group">
<label for="pincode">Pin Code</label>
<input type="number" class="form-control" id="pincode" name="pincode" placeholder="pincode">
</div>
<div class="form-group">
<label for="email">Email id</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Email Id">
</div>
<div class="form-group">
<label for="dob">Date of Birth</label>
<input type="date" class="form-control" id="date" name="date" >
</div>
<div class="form-group">
<label for="mobile">Mobile no.</label>
<input type="number" class="form-control" id="mobile" name="mobile" placeholder="mobile number" >
</div>
<button type="submit" class="btn btn-primary btn-lg btn-block">Save</button>
<input type="hidden" onclick = "jump()" name="submitted" value="1">
</form>
</div>
</div>
</div>
</body>
</html>
navigation.php下面第15行
<nav class="navbar navbar-inverse" role="navigation">
<div class="container">
<ul class="nav navbar-nav">
<li><a href="#">Home</a></li>
<li><a href="#">Contact us</a></li>
<li><a href="reg1.php?">registration</a></li>
<li><a href="stock.php?">farm stock</a></li>
</ul>
<div class="pull-right">
<ul class="nav navbar-nav">
<li class="dropdown">
**line 15 error** <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo$_SESSION['user_name'];?><span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="logout.php">Logout</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
答案 0 :(得分:0)
如果您已经为页面提供任何,则无法更改标题(即重定向)。例如,您无法回复<p>hello</p>
,然后执行header('Location....
,因为您已经提供了一些内容。
将reg1.php更改为此,它应该有效:
<?php
#start session
session_start();
#database connection
include('../config/connection.php');
include('../config/setup.php');
if (!isset($_SESSION['user_name'])) {
header('location:login.php');
}
if (isset($_POST['submitted'])==1) {
$name = mysqli_real_escape_string($dbc, $_POST['name']);
$fname = mysqli_real_escape_string($dbc, $_POST['fathername']);
$postadd = mysqli_real_escape_string($dbc, $_POST['postadd']);
$personaladd= mysqli_real_escape_string($dbc, $_POST['personaladd']);
$sex = mysqli_real_escape_string($dbc, $_POST['sex']);
$clients = mysqli_real_escape_string($dbc, $_POST['clients']);
$state = mysqli_real_escape_string($dbc, $_POST['state']);
$city = mysqli_real_escape_string($dbc, $_POST['city']);
$pincode = mysqli_real_escape_string($dbc, $_POST['pincode']);
$email = mysqli_real_escape_string($dbc, $_POST['email']);
$date = mysqli_real_escape_string($dbc, $_POST['date']);
$mobile = mysqli_real_escape_string($dbc, $_POST['mobile']);
$q = "INSERT INTO registration (name, fname, postadd, personaladd, sex, clients, state, city, pincode, email, dob, mobile) VALUES ('$name', '$fname', '$postadd', '$personaladd', '$sex', '$clients', '$state', '$city', '$pincode', '$email', '$date', '$mobile')" ;
$r = mysqli_query($dbc, $q);
if($_POST['clients']=="farmer"){
$b = "insert into message values((SELECT reg_id FROM registration ORDER BY reg_id DESC LIMIT 1),(select mobile from registration where reg_id ORDER BY reg_id DESC LIMIT 1),(select Company from seed_testing where State=(select State from registration ORDER BY reg_id DESC LIMIT 1)));";
$c = mysqli_query($dbc, $b);
}
if ($r){
$value_to_page = array(
"farmer" => 'farm.php',
"investor" => 'interest.php',
);
if(isset($_POST['submitted'])){
// process other fields like $_POST['some-other']
if(isset($_POST['clients']) && isset($value_to_page[$_POST['clients']])){
header('Location: '.$value_to_page[$_POST['clients']]);
return;
}
}
}
else{
echo 'please enter some data or error :'.mysqli_error($dbc);
echo '<p>'.$q.'</p>';
}
}
?>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo 'Registration | '.$site_title; ?></title>
<?php include('../config/css.php'); ?>
<?php include('../config/js.php'); ?>
</head>
<body>
<?php include('../template/navigation.php'); ?>
<h2><center><strong>General Information </strong></center></h2>
<div id="wrap">
<div class="container">
<div class="col-md-6 col-md-offset-3">
<form action="reg1.php" method="post" >
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="First name and Surname" required>
</div>
<div class="form-group">
<label for="fathername">Father Name</label>
<input type="text" class="form-control" id="fathername" name="fathername" placeholder="fathername">
</div>
<div class="form-group">
<label for="postadd">Postal Address</label>
<textarea type="text" class="form-control" id="postadd" name="postadd" placeholder="postal Address"></textarea>
</div>
<div class="form-group">
<label for="personaladd">Personal Address</label>
<textarea class="form-control" id="personaladd" rows="5" name="personaladd" placeholder="personal address"></textarea>
</div>
<div class="form-group">
<label class="radio-inline">
<input type="radio" name="sex" id="male" value="Male"> Male
</label>
<label class="radio-inline">
<input type="radio" name="sex" id="female" value="Female"> Female
</label>
</div>
<div class="form-group">
<label class="radio-inline">
<input type="radio" name="clients" id="farmer" value="farmer"> farmer
</label>
<label class="radio-inline">
<input type="radio" name="clients" id="investor" value="investor"> investor
</label>
</div>
<div class="form group">
<label>state</label>
<select class="form-control" name="state">
<option selected="" ></option>
<option value="Andra Pradesh">Andra Pradesh</option>
<option value="Arunachal Pradesh">Arunachal Pradesh</option>
<option value="Assam">Assam</option>
<option value="Bihar">Bihar</option>
<option value="Chhattisgarh">Chhattisgarh</option>
<option value="Delhi">Delhi</option>
<option value="Goa">Goa</option>
<option value="Gujarat">Gujarat</option>
<option value="Haryana">Haryana</option>
<option value="Himachal Pradesh">Himachal Pradesh</option>
<option value="Jammu and Kashmir">Jammu and Kashmir</option>
<option value="Jharkhand">Jharkhand</option>
<option value="Karnataka">Karnataka</option>
<option value="Kerala">Kerala</option>
<option value="Madya Pradesh">Madya Pradesh</option>
<option value="maharashtra">Maharashtra</option>
<option value="Manipur">Manipur</option>
<option value="Meghalaya">Meghalaya</option>
<option value="Mizoram">Mizoram</option>
<option value="Nagaland">Nagaland</option>
<option value="Orissa">Orissa</option>
<option value="Punjab">Punjab</option>
<option value="Rajasthan">Rajasthan</option>
<option value="Sikkim">Sikkim</option>
<option value="Tamil Nadu">Tamil Nadu</option>
<option value="Tripura">Tripura</option>
<option value="Uttaranchal">Uttaranchal</option>
<option value="Uttar Pradesh">Uttar Pradesh</option>
<option value="West Bengal">West Bengal</option>
</select>
</div>
<div class="form-group">
<label for="name">City</label>
<input type="text" class="form-control" id="city" name="city" placeholder="Enter your city">
</div>
<div class="form-group">
<label for="pincode">Pin Code</label>
<input type="number" class="form-control" id="pincode" name="pincode" placeholder="pincode">
</div>
<div class="form-group">
<label for="email">Email id</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Email Id">
</div>
<div class="form-group">
<label for="dob">Date of Birth</label>
<input type="date" class="form-control" id="date" name="date" >
</div>
<div class="form-group">
<label for="mobile">Mobile no.</label>
<input type="number" class="form-control" id="mobile" name="mobile" placeholder="mobile number" >
</div>
<button type="submit" class="btn btn-primary btn-lg btn-block">Save</button>
<input type="hidden" onclick = "jump()" name="submitted" value="1">
</form>
</div>
</div>
</div>
</body>
</html>