当我重新加载/刷新表单时数据消失。
我的获取数据的查询..
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;
}
我发送数据的表单
<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>
我填充数据的表单
<?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'
?>
我不知道为什么表单变空,意味着当我重新加载页面时数据被擦除..
任何帮助将不胜感激。
答案 0 :(得分:0)
if(isset($_POST['stu-view']))
{
$_SESSION['stusearch'] = $_POST['stu-view'];
}
// Move this out
if(isset($_SESSION['stusearch'])){
$gtstu->stsearch = $_SESSION['stusearch'];
}
我认为您不会重新发送表单中的数据。因此,您没有从会话中获取数据,因为您只在发送数据时查看会话,
答案 1 :(得分:0)
假设您正在谈论自己的表格&#34;从&#34;发送数据,您应该在文本框中添加一个值属性(stu-view)并用提交的搜索值填充它,即添加:
value="<?php echo $_SESSION['stusearch']; ?>"
答案 2 :(得分:0)
填充数据的表单永远不会起作用,原因很简单:你没有包含session_start();在代码的顶部。因此,在页面刷新时,会话将被销毁。
我的错误:我忘记在页面顶部添加session_start()
。