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

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答