0

I am having a problem getting back to my page with a unique id after processing a data

this first part of the code is redirecting into the page getting the unique id of the folder

  <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>

this is the folder.php with unique id

<?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>

this code below is my problem I don't what should I add in header to get me back in the page with unique 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');
   }
}
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/5741187) – Dharman May 12 '21 at 10:40

2 Answers2

1

if the processing requires redirecting to another page then include the unique ID in the url using GET method then include it in header function on php

0

I already fix the problem thanks in giving me an idea i just put

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