我想創建幾個與數據庫交互的頁面。警告:無法修改標題信息:標題已發送
這裏是我的代碼,CSS:
<HTML>
<HEAD>
<TITLE>Modify Employee's Information</TITLE>
<style type="text/css">
.form_style {
margin:10px auto;
max-width: 400px;
padding: 20px 12px 10px 20px;
font: 13px "Lucida Sans Unicode", "Lucida Grande", sans-serif;
}
.form_style li {
padding: 0;
display: block;
list-style: none;
margin: 10px 0 0 0;
}
.form_style h1{
text-align: center;
}
.form_style label{
margin:0 0 3px 0;
padding:0px;
display:block;
font-weight: bold;
}
.form_style input[type=text],
.form_style input[type=date],
.form_style input[type=datetime],
.form_style input[type=number],
.form_style input[type=search],
.form_style input[type=time],
.form_style input[type=url],
.form_style input[type=email],
textarea,
select{
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
border:1px solid #BEBEBE;
padding: 7px;
margin:0px;
-webkit-transition: all 0.30s ease-in-out;
-moz-transition: all 0.30s ease-in-out;
-ms-transition: all 0.30s ease-in-out;
-o-transition: all 0.30s ease-in-out;
outline: none;
}
.form_style input[type=text]:focus,
.form_style input[type=date]:focus,
.form_style input[type=datetime]:focus,
.form_style input[type=number]:focus,
.form_style input[type=search]:focus,
.form_style input[type=time]:focus,
.form_style input[type=url]:focus,
.form_style input[type=email]:focus,
.form_style textarea:focus,
.form_style select:focus{
-moz-box-shadow: 0 0 8px #88D5E9;
-webkit-box-shadow: 0 0 8px #88D5E9;
box-shadow: 0 0 8px #88D5E9;
border: 1px solid #88D5E9;
}
.form_style .field-divided{
width: 49%;
}
.form_style .field-short{
width: 18.8%;
text-align: center;
}
.form_style .field-salary{
width:39.4%;
text-align: center;
}
.form_style .field-id{
width: 10%;
text-align: center;
}
.form_style .field-long{
width: 90%;
}
.form_style .field-select{
width: 100%;
}
.form_style .field-textarea{
height: 100px;
}
.form_style input[type=submit], .form_style input[type=button]{
background: #4B99AD;
padding: 8px 15px 8px 15px;
border: none;
color: #fff;
margin: 0 auto;
}
.form_style input[type=submit]:hover, .form_style input[type=button]:hover{
background: #4691A4;
box-shadow:none;
-moz-box-shadow:none;
-webkit-box-shadow:none;
}
.form_style .required{
color:red;
}
</style>
</HEAD>
<BODY>
PHP:
<?php
include 'connection.php';
if (!isset($_POST['edit'])) {
$query = "SELECT * FROM employee_data WHERE emp_id = $_GET[id]";
$result = mysql_query($query);
$emp = mysql_fetch_array($result);
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<ul class="form_style">
<li>
<h1>Modify Employee's Information</h1>
</li>
<li>
<b>Employee ID:</b> <input type="text" name="id" class="field-id" value="<?php echo $emp['emp_id']?>" readonly/>
</li>
<li>
<label>Employee Name</label>
<input type="text" name="inputFname" class="field-divided" placeholder="First" value="<?php echo $emp['f_name'] ?>"/> <input type="text" name="inputLname" class="field-divided" placeholder="Last" value="<?php echo $emp['l_name'] ?>"/>
</li>
<li>
Title <input type="text" name="inputTitle" class="field-short" value="<?php echo $emp['title'] ?>"/> Age <input type="text" name="inputAge" class="field-short" value="<?php echo $emp['age'] ?>"/> Year of Services <input type="text" name="inputYos" class="field-short" value="<?php echo $emp['yos'] ?>"/>
</li>
<li>
Salary <input type="text" name="inputSalary" class="field-salary" value="<?php echo $emp['salary'] ?>"/> Perks <input type="text" name="inputPerks" class="field-salary" value="<?php echo $emp['perks'] ?>"/>
</li>
<li>
Email <input type="email" name="inputEmail" class="field-long" value="<?php echo $emp['email'] ?>"/>
</li>
<li>
<input type="submit" name="edit" value="Modify" />
<p>Change any information as you want, or click Modify directly to save without any change. </p>
<p>p.s. Employee ID is not changeable.</P>
</li>
</ul>
</form>
<?php
if (isset($_POST['edit'])) {
$edit = "UPDATE employee_data SET f_name ='$_POST[inputFname]',"
. "l_name ='$_POST[inputLname]',"
. "title ='$_POST[inputTitle]',"
. "age ='$_POST[inputAge]',"
. "yos ='$_POST[inputYos]',"
. "salary ='$_POST[inputSalary]',"
. "perks ='$_POST[inputPerks]',"
. "email ='$_POST[inputEmail]'"
. "WHERE emp_id = '$_POST[id]'";
mysql_query($edit) or die(mysql_error());
header('Location: index.php');
}
?>
</BODY>
我想這是一個有點亂,我會得到它乾淨多了後,我解決所有功能錯誤。
所以我不明白的是爲什麼它告訴我:
Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/Employee/modify.php:128) in /Applications/XAMPP/xamppfiles/htdocs/Employee/modify.php on line 166
線128只是處理用戶ID,由它傳遞給SQL操作。爲什麼發送標題?一切工作正常,除了頁面給我這個錯誤,並拒絕重定向到主頁面。
此代碼在我向窗體添加一些CSS和樣式之前一直在工作。任何人都可以給我一個想法,他們的主要區別是什麼?
<?php
include 'connection.php';
if (!isset($_POST['edit'])) {
$query = "SELECT * FROM employee_data WHERE emp_id = $_GET[id]";
$result = mysql_query($query);
$emp = mysql_fetch_array($result);
}
?>
<form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Employee ID<input type="text" name ="id" value="<?php echo $emp['emp_id'] ?>" readonly/> <br />
First Name<input type="text" name="inputFname" value="<?php echo $emp['f_name'] ?>" /> <br />
Last Name<input type="text" name="inputLname" value="<?php echo $emp['l_name'] ?>" /> <br />
Title<input type="text" name="inputTitle" value="<?php echo $emp['title'] ?>" /> <br />
Age<input type="text" name="inputAge" value="<?php echo $emp['age'] ?>" /> <br />
Year of Service<input type="text" name="inputYos" value="<?php echo $emp['yos'] ?>" /> <br />
Salary<input type="text" name="inputSalary" value="<?php echo $emp['salary'] ?>" /> <br />
Perks<input type="text" name="inputPerks" value="<?php echo $emp['perks'] ?>" /> <br />
Email<input type="text" name="inputEmail" value="<?php echo $emp['email'] ?>" /> <br />
<br />
<input type="submit" name="edit" value="Modify The Employee"/> <br />
</form>
<?php
if (isset($_POST['edit'])) {
$edit = "UPDATE employee_data SET f_name ='$_POST[inputFname]',"
. "l_name ='$_POST[inputLname]',"
. "title ='$_POST[inputTitle]',"
. "age ='$_POST[inputAge]',"
. "yos ='$_POST[inputYos]',"
. "salary ='$_POST[inputSalary]',"
. "perks ='$_POST[inputPerks]',"
. "email ='$_POST[inputEmail]'"
. "WHERE emp_id = '$_POST[id]'";
mysql_query($edit) or die(mysql_error());
header("Location: index.php");
}
?>
你的代碼是完全受到SQL注入攻擊。 – Boann