2016-06-03 2 views
1

양식을 새로 고침하거나 새로 고침하면 데이터가 사라집니다.페이지 새로 고침 후 데이터가 사라집니다.

public function view_detail() 
    { 
     $qry=$this->conn->prepare("SELECT * FROM student_detail WHERE Student_Cnic=:search OR Student_Name=:search"); 
     $qry->bindParam(':search',$this->stsearch); 

     $qry->execute(); 
     return $qry; 
    } 

내가 데이터

<?php 
include 'header.php'; 
include 'config.php'; 
include 'classes.php'; 
$database=new Database(); 
$db=$database->getConnection(); 
$gtstu=new stu_sys($db); 

if(isset($_POST['stu-view'])) 
{ 
$_SESSION['stusearch'] = $_POST['stu-view']; 
if(isset($_SESSION['stusearch'])){ 
    $gtstu->stsearch = $_SESSION['stusearch']; 
} 
} 
$fth = $gtstu->view_detail(); 


?> 


<div class="row"> 
    <div class="col-lg-12"> 

     <div class="col-lg-2"></div> 
     <div class="col-lg-8" style="margin-top: 10%;"> 

      <table class="table table-responsive table-bordered"> 
       <th>Image</th> 
       <th>Name</th> 
       <th>Cnic</th> 
       <th>Department</th> 
       <th>View Detail</th> 
       <?php while($row = $fth->fetch(PDO::FETCH_OBJ)):?> 
       <tr> 
        <td><img src="images/<?php echo $row->Student_Image; ?>" alt=""/></td> 
        <td><?php echo $row->Student_Name ?></td> 
        <td><?php echo $row->Student_Cnic ?></td> 
        <td><?php echo $row->Deprt ?></td> 
        <td><a href="#">View More Detail</a></td> 
       </tr> 
       <?php endwhile;?> 
      </table> 
      <a href="dashboard.php" class="btn btn-primary">Back TO Dashboard</a> 
     </div> 
     <div class="col-lg-2"></div> 

    </div> 

</div> 











<?php 
include 'footer.php' 
?> 
을 채우는하고 내가 보내고 데이터

<form action="view.php" method="post" id="view_form"> 
          <br> 
          <label for="">View By Name or CNIC</label> 
          <input type="text" class="form-control" name="stu-view" id="stu-view" placeholder="Student Name or CNIC"><br> 

          <input type="submit" name="view-detail" id="view-detail" class="btn btn-success" value="Enroll"><br> 
         </form> 

양식에서 양식 점점 데이터에 대한 나의 질문 ..

양식이 비어있는 이유를 모르겠습니다. 페이지를 새로 고침하면 데이터가 지워집니다.

도움이 되겠습니다.

+0

양식을 제출하면 데이터가 PHP 서버에 제출되고 페이지를 새로 고침하면 데이터가 손실됩니다. 이 목적으로 세션을 사용해야합니다. –

+2

데이터가 채워지는 양식은 간단한 이유 중 하나로 결코 작동하지 않습니다 : 코드 상단에'session_start();'가 포함되어 있지 않습니다. 따라서 페이지 새로 고침시 세션이 삭제됩니다. – icecub

+0

감사합니다 @icecub 나는 페이지에 세션을 추가하는 것을 잊어 버렸습니다. – msz

답변

0
if(isset($_POST['stu-view'])) 
{ 
    $_SESSION['stusearch'] = $_POST['stu-view'];  
} 

// Move this out 
if(isset($_SESSION['stusearch'])){ 
    $gtstu->stsearch = $_SESSION['stusearch']; 
    } 

양식에 데이터를 다시 보내지 않는다고 가정합니다. 따라서 데이터가 전송 된 경우에만 세션을보고 있기 때문에 세션에서 데이터를 가져 오지 못합니다.

+0

여전히 같은 결과 – msz

0

"데이터를 보낸 사람"이라고 가정하면 텍스트 상자에 값 속성을 추가해야합니다 (STU-보기)와 제출 된 검색 값으로 채 웁니다 즉 추가

value="<?php echo $_SESSION['stusearch']; ?>" 
0

양식을 데이터가 하나의 단순한 이유로 작동하지 않습니다 채워지입니다 : 당신은()으로 session_start를 포함하지 않는; 귀하의 코드 상단에. 따라서 페이지 새로 고침시 세션이 삭제됩니다.

내 실수 : 나는 페이지의 상단에 session_start()를 추가하는 것을 잊었다.

관련 문제