动态表单php没有传递值

时间:2017-03-07 17:04:44

标签: php debugging variables dynamic

我有一个名为room的MySQL表,其中包含id和房间名称。我动态生成所有这些按钮。想法是获得所有房间的列表,tab-2-room.php显示所有房间(很多工作)。用户点击房间,下一页显示可以在该房间中找到的所有项目的列表。在这一点上,我只需要传递变量,这是行不通的。我已经完成了这十万次,这次表单不想传递任何值。

如果您需要任何其他信息,请询问我可以提供它。有人可以在这里发现错误吗?

controller.php文件包含new_room函数,该函数位于下方。

以下文件名为tab-2-room.php

<?php
session_start ();
include_once 'controller.php';
if(isset($_POST['room'])) {  
  header('location: tab-2-items.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <title>Tab 2 Room - Selection</title>
</head>
<body>
    <div class="container">       
        <form enctype="multipart/form-data" method="post" action="">            
            <h1>ROOMS</h1>          
            <?php room_new(); ?>
            <h2></h2>
        </form>        
    </div>  
</body>
</html>

以下文件名为tab-2-item.php

<?php
session_start ();
include_once 'controller.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <title>Tab 2 items - Data Entry</title>
</head>
<body>
    <div class="container">       
        <form enctype="multipart/form-data" method="post" action="">            
            <h1>ROOM ITEMS </h1>
            <?php 
                global $query;          
                var_dump($_POST);
                $roomId = $_POST['room-id'];                
                echo 'this is room id:'.$roomId.'</br>';
                //query to get all items that belong to the room-id                     
            ?>  
        </form>        
    </div>  
</body>
</html>

PHP

function room_new(){    
    global $query;              
    //Dinamically displays values of size_standard table
    $moveType = $_SESSION['move-type'];
    $queryRoom = "SELECT * FROM room WHERE room_type = $moveType OR room_type = 3"; 
    $resultRoom = $query->query($queryRoom) or die ('Could not execute Room query'. mysqli_error($query));      
    for ($i = 1; $i <= $resultRoom->num_rows; $i++) {
        $rowRoom = $resultRoom->fetch_assoc();
        extract($rowRoom);
            echo 'id: '.$id;
            echo ' counter: '.$i;
            echo "<input type='submit' class='' name='room' value='$room_name'><br />";             
            echo "<input type='hidden' name='room-id' value='$id'>";            
    }   
} 

全局var查询设置如下:

$GLOBALS['query'] = new mysqli($host, $username, $password, $db_name) or die("cannot connect");

global $query;
if ($query->connect_errno) {
  printf("Connect failed: %s\n", $query->connect_error);  
  exit();
}

0 个答案:

没有答案