douping1581 2012-07-14 16:55
浏览 60
已采纳

我无法将从$ _GET []收到的值分配给变量

I am trying to pick the id using the $_GET[] and assign it to a variable however it does not work. when i try to echo $_GET[] directly it works fine the ID is displayed on the page, however when i assign it to a variable and try to echo it, it wont work. for example this wont work:

$sel_hotel = $_GET[];
echo $sel_hotel; 

The code looks fine there is no any problem with it but it just don't pass that value to the variable i believe there may be something wrong with my php.ini file but i am not sure. i am using PHP Version 5.4.3. Please Help . Thank you very Much

<?php 
if(isset($_GET['hotl'])){
 $sel_hotel = $_GET['hotl']; 
 $sel_hotel ="";
 echo   $sel_hotel;
}elseif(isset($_GET['room'])){
 $sel_room = $_GET['room'];
 $sel_room ="";
 echo $sel_room;
}else{
$sel_hotel ="";
$sel_room ="";
}
echo  $sel_hotel;

?>
<?php require_once("includes/header.php");?>
<?php require_once("includes/function.php");?>
<?php //require_once("TheDatabase.php")?>
<?php $connection = mysql_connect("localhost","root","root");
       if(!$connection){
       die("Database Connection Failed :". mysql_error());
       }else{                               
              $db_select = mysql_select_db("travelnstay", $connection);
              if(!$db_select){
              die("Database Selection Failed:". mysql_error());
              }
        }
?>
<div class="Calign">
<div class="mar">
<div>
<p>Menu</p>
<?php
               $hotel_set = select_all_hotels(); 
                 while($hotel = mysql_fetch_array($hotel_set)){
                     echo "<p class=\"mar\"><a href=\"admincontent.php?hotl=" . 

urlencode($hotel["hotel_id"]).

                     "\">{$hotel["hotel_name"]}</a></span></p>";
                     $room_set = room_by_id($hotel["hotel_id"]);
                     echo "<ul>";
                     while($room= mysql_fetch_array($room_set)){
                     echo "<li><a href=\"admincontent.php?room=". urlencode($room["room_id"]).
                     "\">{$room["room_type"]}</a></li>";                  
                     echo"</ul>";
                     }  
                }


     echo "<p> Its is suppose to be here".$sel_hotel."</p>"; 
     echo "<p>". $sel_room. "</p>";


  ?>


</div><!--end of the mar-->
</div><!--end of the Calign-->
</body>

</html>
  • 写回答

3条回答 默认 最新

  • douluanzhao6689 2012-07-14 16:57
    关注

    Every time you set variables from the $_GET, you erase them after...

    Try:

    <?php 
      $sel_hotel = "";
      $sel_room  = "";
    
      if(isset($_GET['hotl']))
      {
        $sel_hotel = $_GET['hotl']; 
        echo $sel_hotel;
      }
      elseif(isset($_GET['room']))
      {
        $sel_room = $_GET['room'];
        echo $sel_room;
      }
    
      echo $sel_hotel;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决