简体   繁体   English

如何存储从 isset($_GET['Something']) 获得的值以在 .php 页面中重复使用

[英]How can I store the value I get from the isset($_GET['Something']) for repeated use within the .php page

<?php

include_once("Globals.php");
global $model;

I want to capture the $order_id value from the $_GET['claim_order'] for future re-use.我想从 $_GET['claim_order'] 中捕获 $order_id 值以供将来重用。

if(isset($_GET['claim_order'])){
   $order_id = $_GET['claim_order'];

}

for example the value saved in the $order_id variable is not available for repeat use on the current page.例如,$order_id 变量中保存的值不能在当前页面上重复使用。


?>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Caregiver Claims Order</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <!-- Font Awesome -->
  <link rel="stylesheet" href="../../plugins/fontawesome-free/css/all.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../../dist/css/adminlte.min.css">
  <!-- Google Font: Source Sans Pro -->
  <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">

    <!-- Main Sidebar Container -->
    <aside class="main-sidebar sidebar-dark-primary elevation-4">
        <!-- Sidebar -->
        <div class="sidebar">
            <!-- Sidebar user (optional) -->
            <div class="user-panel mt-3 pb-3 mb-3 d-flex">        
                <div class="info">
                    <a href="#" class="d-block">SESSION: Caregiver</a>
                </div>
            </div>

            <!-- Sidebar Menu -->
            <nav class="mt-2">
                <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
                </ul>
            </nav>
            <!-- /.sidebar-menu -->
        </div>
        <!-- /.sidebar -->
    </aside>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header" style="padding: 0px 0px 0px 0px" >
            <div class="container-fluid " style="padding: 0px 0px 0px 0px" >
                <div class ="row">
                    <div class="col">
                        <h1>Order#<?php
                          global $order_id;
                          echo (int)$order_id;
                        ?></h1>
                    </div>
                    <div class ="col-auto">

                        <a href ="CaregiverCODetailView.php?button_claim=$care_giver_id">
                            <input type="submit" name="button_claim" class="btn btn-primary"></input>
                        </a>
                        <?php 
                            if(isset($_GET["button_claim"])){

for example in the next 3 lines I try to use it but it returns the wrong value of 0 instead the correct value corresponding to the "button_claim".例如,在接下来的 3 行中,我尝试使用它,但它返回错误的值 0,而不是对应于“button_claim”的正确值。

I want to be able to refer to the value even if I refresh the.php page.即使我刷新 .php 页面,我也希望能够引用该值。

All I want to do is use that $order_id value in a SQL query.我要做的就是在 SQL 查询中使用该 $order_id 值。 It basically indicates the ID# of the order in question.它基本上表示相关订单的 ID#。

                                $care_giver_id = $model->getCurrentUserId();
                                global $order_id;



                                $sql = "UPDATE `order` SET `care_giver_id` = '$care_giver_id'  WHERE `order_id` = '$order_id'";

                                if(!mysqli_query($conn, $sql)){
                                    header("Location: fail.php");
                                }else{
                                    header("Location: CaregiverCODetailView.php");
                                }
                            }
                        ?>
                    </div>
                </div>
                <div class="row" style="min-height:71vh" style="min-width:100vw">
                    <div class= "col" style="min-height:71vh" style="min-width:100vw">
                        <table id="example4" class="table table-borderless table-hover">
                            <?php

                                global $conn;
                                global $order_id;

                                if ($conn->connect_error) {
                                    die("Connection failed: " . $conn->connect_error);
                                }

                                $sql  = "SELECT";
                                $sql .= " `medication`.`name` as `name`,";
                                $sql .= " `medication`.`physical_form` as `form`,";
                                $sql .= " `medication`.`units` as `units`,";
                                $sql .= " `break_down`.`administer_time` as `time`,";
                                $sql .= " `break_down`.`quantity` as `quantity`";
                                $sql .= " FROM `break_down`";
                                $sql .= " JOIN `medication` on (`medication`.`medication_id` = `break_down`.`medication_id`)";
                                $sql .= " WHERE `break_down`.`order_id` = '$order_id'";


                                $result = $conn->query($sql);
                                echo "<id='example2'>";
                                echo "<tbody>";
                                if ($result->num_rows > 0) {
                                    while($row = $result->fetch_assoc()) {
                                        echo "<tr>";
                                            echo "<td>" . $row['name'] . "</td>";
                                            echo "<td>" . $row['quantity'] . $row['units']. "</td>";
                                            echo "<td>" . $row['form'] . "</td>";
                                            echo "<td>" . $row['time'] . "</td>";
                                        echo "</tr>";
                                    }
                                    echo "</tbody>";
                                    echo "</table>";
                                } else {
                                    echo "</tbody>";
                                    echo "</table>";
                                    echo "<h4>ORDERS DATABASE EMPTY</h4>";
                                }
                            ?>
                    </div>
                </div>
                <div class="row" style="min-height:15vh" style="min-width:100vw">
                    <div class= "col" style="background-color:orange" style="min-height:15vh" style="min-width:100vw" >
                        <?php
                            global $conn;

                            if ($conn->connect_error) {
                                die("Connection failed: " . $conn->connect_error);
                            }

                            $sql = " select " ;
                            $sql .=     " `patient`.`first` as `first`,";
                            $sql .=     " `patient`.`last` as `last`,";
                            $sql .=     " `order`.`order_id` as `order_id`,";
                            $sql .=     " `order`.`date` as `datefield`";
                            $sql .= " from `patient`";
                            $sql .= " join `order` on (`order`.`patient_id` = `patient`.`patient_id`)";
                            $sql .= " where `order`.`order_id` =  '$order_id'";

                            $result = $conn->query($sql);

                            if ($result->num_rows > 0) {
                                while($row = $result->fetch_assoc()) {
                                    echo "<div class='row '>";
                                        echo "<div class ='col '>";
                                            echo "<h3>Patient</h3>";
                                            echo "<h5>" . $row['first'] . " " . $row['last'] . "</h5>";
                                        echo "</div>";
                                        echo "<div class = 'col-auto '>";
                                            echo "<h3>Date Created</h3>";
                                            echo "<h5>" . $row['datefield'] . "</h5>";
                                        echo "</div>";
                                    echo "</div>";
                                }
                            }
                        ?> 
                    </div>
                </div>     
            </div>
            <!-- /.container-fluid -->
        </section>
    </div>
</div>
<!-- ./wrapper -->

If you want to store some short-term data, PHP sessions would be a sufficient solution.如果您想存储一些短期数据,PHP 会话将是一个足够的解决方案。 Keep in mind that this data will only last as long as your session lasts.请记住,这些数据只会持续到您的 session 持续的时间。

session_start();
$_SESSION['order_id'] = $_GET['claim_order'];

For a longer-term storage solution, consider storing the data in a database like MySQL or in a file (make sure to keep this file out of the web directory if it's holding private information).对于长期存储解决方案,请考虑将数据存储在 MySQL 等数据库或文件中(如果该文件包含私人信息,请确保将此文件保存在 web 目录之外)。

You can use the setcookie('name_of_cookie', $value);您可以使用setcookie('name_of_cookie', $value); and get this data using $_COOKIE('name_of_cookie');并使用$_COOKIE('name_of_cookie');获取此数据. . after this you can use the unset($_COOKIE('name_of_cookie'));在此之后,您可以使用unset($_COOKIE('name_of_cookie'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM