회원정보 수정시 headers 에러문의
본문
회원관리 하는 소스를 하나 퍼와서 공부중입니다.
예전 소스라서 그런지 수정할데가 많더군요. 없는 지식으로 조금씩 수정해나가고 있는데.. 막히는게 있어서 문의드립니다.
<?php
include ('db.php');
include ('header.php');
$ID=$_GET['id'];
?>
<body>
<div class="container">
<div class="hero-unit-header">
<div class="container-con">
<!-- end banner & menunav -->
<div class="container">
<div class="row-fluid">
<div class="span12">
<div class="row-fluid">
<div class="span3"></div>
<div class="span6">
<div class="hero-unit-3">
<center>
<?php
$query=mysqli_query($con,"select * from student where student_id='$ID'")or die(mysqli_error());
$row=mysqli_fetch_array($query);
?>
<form class="form-horizontal" method="post" enctype="multipart/form-data" style="float: right;">
<legend><h4>Edit</h4></legend>
<h4>Image</h4>
<hr>
<div class="control-group">
<label class="control-label" for="inputPassword">
<?php if($row['location'] != ""): ?>
<img src="upload/<?php echo $row['location']; ?>" width="100px" height="100px" style="border:1px solid #333333;">
<?php else: ?>
<img src="images/default.png" width="100px" height="100px" style="border:1px solid #333333;">
<?php endif; ?>
</label>
<div class="controls">
<input type="file" name="image" style="margin-left:27px;">
<button type="submit" name="image" class="btn btn-success" style="margin-top: 20px; margin-right: 131px;">Update</button>
</div>
</div>
<hr>
<h4>Personal Information</h4>
<hr>
<div class="control-group">
<label class="control-label" for="inputPassword">FirstName:</label>
<div class="controls">
<input type="text" name="fname" required value=<?php echo $row['fname']; ?>>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">MiddleName:</label>
<div class="controls">
<input type="text" name="mname" required value=<?php echo $row['mname']; ?>>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">LastName:</label>
<div class="controls">
<input type="text" name="lname" required value=<?php echo $row['lname']; ?>>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Address:</label>
<div class="controls">
<input type="text" name="address" required value=<?php echo $row['address']; ?>>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Email:</label>
<div class="controls">
<input type="text" name="email" value=<?php echo $row['email']; ?>>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" name="update" class="btn btn-success" style="margin-right: 65px;">Save</button>
<a href="index.php" class="btn">Back</a>
</div>
</div>
</form>
<?php
$id=$_REQUEST['id'];
if (isset($_POST['image'])) {
//image
$image = $_FILES["image"] ["name"];
$image_name= addslashes($_FILES['image']['name']);
$size = $_FILES["image"] ["size"];
move_uploaded_file($_FILES["image"]["tmp_name"],"upload/" . $_FILES["image"]["name"]);
$location=$_FILES["image"]["name"];
mysqli_query($con, " UPDATE student SET location='$location' WHERE student_id = '$id' ")or die(mysqli_error());
header('location:index.php');
}
?>
<?php
$id=$_REQUEST['id'];
$result = mysqli_query($con, "SELECT * FROM student WHERE student_id = '$id'");
$test = mysqli_fetch_array($result);
if (!$result)
{
die("Error: Data not found..");
}
$fname= $test['fname'];
$mname= $test['mname'];
$lname= $test['lname'];
$address= $test['address'];
$email= $test['email'];
if (isset($_POST['update'])) {
$fname_save= $_POST['fname'];
$mname_save= $_POST['mname'];
$lname_save= $_POST['lname'];
$address_save= $_POST['address'];
$email_save= $_POST['email'];
mysqli_query($con, "UPDATE student SET fname = '$fname_save' , mname = '$mname_save' , lname ='$lname_save',
address = '$address_save' , email ='$email_save' WHERE student_id = '$id'") or die(mysqli_error());
//header("Location: index.php");
header('location: http://localhost/index.php');
exit;
}
?>
</center>
</center>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
수정하는 소스입니다.
저기서 업데이트를 한뒤 header('location:index.php'); 이동을 못하고 에러가 납니다.
데이터는 제대로 수정돼서 DB에 들어갑니다.
인터넷 뒤져보니 호스트마다 주소를 넣어야 하기도 한다길래 header('location: http://ID.dothome.co.kr/test/index.php'); 이렇게 해도 마찮가지네요.
저부분이 문제가 아닌거 같은데.. 회원추가 같은건 제대로 동작하거든요..
수정:
회원관리 소스 출처 : https://www.happycgi.com/16130
혹시 예제로 쓰기에 좋은 소스가 있다면 소개 부탁드려요.. 이 소스는 손볼게 많고 제 입장에선 좀 복잡하네요.
!-->
답변 1
header가 사용되기 전에 출력이 있어서는 안됩니다
그러니 화일 상단에서 무언가 출력되기 전에 소스가 위치해야 합니다
include ('header.php'); <--여기서도 html태그가 있을테니 이 코드 보다 먼저 넣어야 합니다
답변을 작성하시기 전에 로그인 해주세요.