如何返回具有唯一id的页面



在处理数据后,我在返回具有唯一id的页面时遇到问题

代码的第一部分重定向到页面,获取文件夹的唯一id

<a href="folder.php?fldid=<?= $row['id'] ?>"><img src="<?= $row['folderimage'];?>" onerror="this.src='images/folder.png'"  class="card-img-top"  height="160" ></a>
<div class="card-img">
<h6 style="text-align: center;"><?= $row['foldername'];?></h6>

这是具有唯一id 的folder.php

<?php
require'config.php';
session_start();
if(isset($_GET['fldid'])){
$folder_id=$_GET['fldid'];
$sql="SELECT * FROM file_folder WHERE id='$folder_id'";
$result=mysqli_query($conn,$sql);
$row=mysqli_fetch_array($result);
$folder_name=$row['foldername'];
}
?>
<!DOCTYPE html>
<html>
<head>
<title>BSU</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="file.css">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" ><!-- FOR FONT AWESOME ICON-->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"><!-- for css bootsrap 4 -->
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>

<body class="bdy">

<div class="container-fluid">
<div class="row">
<div class="col-lg-3">
<hr>
<ul class="list-group">
<li class="list-group-item">
<div class="form-check">
<button class="btn btn-primary btn-lg btn-block" onclick="openFormfld()">Add Folde with Link</button>
</div>
</li>
<!-- para mag pop up ang add file form-->
<div class="form-popup" id="myFolderForm">
<form action="process.php" method="POST" enctype="multipart/form-data" class="form-container">
<!-- para ma notify if success or may error sa pag add ng file-->
<div style="display:<?php if(isset($_SESSION['showFilerror'])){echo $_SESSION['showFilerror'];}else { echo'none'; } unset($_SESSION['showFilerror']);  ?>"  
class="alert alert-danger alert-dismissible  text-center mt-3">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<strong><?php if(isset($_SESSION['filemess'])){echo $_SESSION['filemess'];} unset($_SESSION['showFilerror']);  ?></strong>
</div>
<!-- end of notif -->
<input type="hidden" name="folderid" value="<?= $folder_id; ?>">
<label for="folder"><b>Folder</b></label>
<input type="text" placeholder="Enter Folder Name" name="fldname"required>
<label for="link"><b>Link</b></label>
<input type="text" placeholder="Enter Link" name="link" required>

<label for="image"><b>Image For Folder</b></label>
<input type="file" name="image">


<button style="margin-top: 15px;" type="submit" name="folderlinkbtn" class="btn btnsub">Save</button>
<a href="" class="btn cancel" onclick="closeFormfld()">Close</a>
</form>
</div>
</ul>
</div>
<!-- para ma display ang folders -->
<div class="col-lg-9">
<!-- para ma notify pag successfull  pag update-->
<div style="display:<?php if(isset($_SESSION['showAlert'])){echo $_SESSION['showAlert'];}else { echo'none'; } unset($_SESSION['showAlert']);  ?>"  
class="alert alert-success alert-dismissible  text-center mt-3">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<strong><?php if(isset($_SESSION['message'])){echo $_SESSION['message'];} unset($_SESSION['showAlert']);  ?></strong>
</div>
<!-- para ma notify pag hinde successfull  pag update-->
<div style="display:<?php if(isset($_SESSION['showError'])){echo $_SESSION['showError'];}else { echo'none'; } unset($_SESSION['showError']);  ?>"  
class="alert alert-danger alert-dismissible  text-center mt-3">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<strong><?php if(isset($_SESSION['error'])){echo $_SESSION['error'];} unset($_SESSION['showError']);  ?></strong>
</div>
<!-- end of notif -->
<h5 class="text-center" id="textChange"><?= $folder_name; ?> Folder</h5>
<hr>
<div class="row" id="result">
<?php    
$sql="SELECT * FROM folder_link WHERE folder_id='$folder_id'";
$result=$conn->query($sql);
while($row=$result->fetch_assoc()){
?>


<div class="col-md-3 mb-2">
<div class="card-deck">
<div style="background-color:#f3f4ed " class="card border-secondary">
<div class="btn-group">
<button style="float: right;" class="btn btn-success dropdown-toggle" id="showhidereply" data-toggle="dropdown" aria-haspopup="true" data-id="<?= $row['id'];?>"></button>
<div class="dropdown-menu" id="replycomment-<?= $row['id'];?>">
<a class="dropdown-item refold"  data-id="<?= $row['id'];?>" >Rename Folder</a>
<a class="dropdown-item chgimg"  data-id="<?= $row['id'];?>" >Change Folder Picture</a>
<a href="process.php?removefld=<?= $row['id'] ?>"class="dropdown-item " onclick="return confirm('Are you Sure you want remove this Link Folder = <?= $row['foldername'];?>');">Delete Folder</a>
</div>
</div>
<a href="<?= $row['folder_links'];?>" target="_blank"><img src="<?= $row['folder_image'];?>" onerror="this.src='images/folder.png'"  class="card-img-top"  height="160" ></a>
<div class="card-img">
<h6 style="text-align: center;"><?= $row['folder_name'];?></h6>

<!-- para sa update folder name pop up-->
<div class="pop-up"  id="upd-<?= $row['id'];?>">
<div class="popup-content">
<form action="process.php"  method="POST">
<p style="text-align: center;">Rename Folder</p>
<input type="hidden"  name="idd" value="<?= $row['id'];?>"> 
<input class="newfold" type="text" name="updatefolder" placeholder="Enter New Folder Name" required>
<a href="" class="btn popbtn">Close</a>
<button type="submit" name="updatebtnfld" class="btn popbtn">Update</button>
</form>
</div>
</div>
<!-- end sa update folder name pop up-->

<!-- para mapalitan ang image  folder pop up-->
<div class="pop-up"  id="img-<?= $row['id'];?>">
<div class="popup-content">
<form action="process.php"  method="POST" enctype="multipart/form-data">
<p style="text-align: center;">Change Folder Iamge</p>
<input type="hidden"  name="idd" value="<?= $row['id'];?>"> 
<input type="file" name="image" required>
<a href="" class="btn popbtn">Close</a>
<button type="submit" name="updimgfld" class="btn popbtn">Update</button>
</form>
</div>
</div>
<!-- end sa update link pop up-->

</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
<!-- end sa folders display-->

</div>
</div>

下面的代码是我的问题,我不知道我应该在标题中添加什么来让我回到具有唯一id 的页面

if(isset($_POST['folderlinkbtn'])){
$fldid = $_POST['folderid'];
$fol = $_POST['fldname'];
$lin = $_POST['link'];
$image='images/'.$_FILES['image']['name'];
$target_dir="images/";
$target_file=$target_dir.basename($_FILES['image']['name']);
move_uploaded_file($_FILES['image']['tmp_name'],$target_file);

$sql="SELECT folder_id FROM folder_link WHERE folder_name ='$fol' LIMIT 1";
$check_query =mysqli_query($conn,$sql);
$count_folder = mysqli_num_rows($check_query);
if($count_folder>0){
$_SESSION['showFilerror']= 'block';
$_SESSION['filemess']="Sorry Folder Name Already Exist";
header('location:folder.php');}
else{
$sql ="INSERT INTO folder_link (folder_id,folder_links,folder_name,folder_image)VALUES('$fldid','$lin','$fol','$target_file')";
$run_query=mysqli_query($conn,$sql);
if($run_query){
$_SESSION['showAlert']= 'block';
$_SESSION['message']="Add File Successful";
header('location:folder.php');
}
else{
$_SESSION['showFilerror']= 'block';
$_SESSION['filemess']="ERROR</strong>";
header('location:folder.php');
}
}
}

如果处理需要重定向到另一个页面,则使用GET方法将唯一ID包含在url中,然后将其包含在php 的头函数中

我已经解决了这个问题,谢谢你给我一个想法,我只是放了

header( "Location: folder.php?fldid={$fldid}" );

最新更新