簡體   English   中英

我試圖使用post方法將變量從PHP傳遞到HTML,但對我不起作用

[英]Im trying to pass a variable from PHP to HTML using post method but it doesn't work with me

這是我的PHP代碼頁

 <?php

    session_start();

    //include database connection
    include_once("dbconn.php");
    //afetr click the submit button the below code will be impelemnted  
    if(isset($_POST['id'])){

    $id=$_POST['id'];
    $Type=$_POST['Type'];
    $Avalibility=$_POST['Avalibility'];

    # insert data into MySQL database

    $sql1 =" update $Type set Reserve=1 where APP_ID=$id ";

    $sql2="INSERT INTO appointment_summary 
    SELECT Fname,Dep_Name,".$_SESSION['login_user'] .",D_ID,Hospital_Name,Hospital_Type,'".$_SESSION['Reason']."',APP_ID,Avalibility
    FROM $Type
    where APP_ID=$id";

    $sql3="select * from appointment_summary  where P_ID=".$_SESSION['login_user'] ." and Availability ='$Avalibility' ";

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

        if ($result->num_rows != 1) {
              $conn->query($sql2);
             $conn->query($sql1);


                      echo "<script>
    alert('Your appointment has been succssfuly add');
    window.location.href='CheckAppoinmnets.php';
    </script>";



         } else {
             $Invalid="<p style=\"color:red;\"> You alrredy have an appointment in this time</p>";
             $_SESSION['Invalid']=$Invalid;  
    }


    }

    //enter code here

    $conn->close();

我在HTML頁面中使用的這段代碼

       <?php 
               if(isset($_POST['id'])){
              echo  $_SESSION['Invalid'];
               } 
              ?>

試試下面的代碼

<?php 
  session_start();        
  if(isset($_REQUEST['id'])){
    echo  isset($_SESSION['Invalid'])?$_SESSION['Invalid']:'';
  } 
?>

如果您在ID和SESSION中均具有值,則應打印

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM