它无法从下拉菜单中显示所选值

时间:2013-01-17 09:41:51

标签: php html mysqli

我有一个应用程序,您可以在这里查看以测试APPLICATION,,但我不得不解决一些我似乎无法弄清楚的问题。

  1. 即使查询正确,也无法显示以下代码中选择的模块:

       <p>
        <strong>Selected Module:</strong><?php $dbModuleNo;?> - <?php$dbModuleName;?> <input type='hidden' value='<?php$_POST["module"];?>'>
        </p>
    
  2. 如果用户从其中一个相关下拉菜单中选择Please Select Module选项并提交后,我该如何显示Please Select an AssessmentPlease Select条消息:

  3. 代码如下(我注释掉了查询):

    <form action="" method="post"> 
                    <?php            
                    /*
                    $moduleactive = 1;
                    $sql = "SELECT ModuleId, ModuleNo, ModuleName FROM Module WHERE ModuleActive = ? ORDER BY ModuleNo"; 
    
                    $sqlstmt=$mysqli->prepare($sql);
                    $sqlstmt->bind_param("i", $moduleactive);
                    $sqlstmt->execute(); 
                    $sqlstmt->bind_result($dbModuleId,$dbModuleNo,$dbModuleName);
                    $sqlstmt->store_result();
                    $sqlnum = $sqlstmt->num_rows();
                    */
                    ?>
                    Module: 
                    <select name="module" id="modulesDrop">
                        <option value="">Please Select</option>
                        <?php
                        while($sqlstmt->fetch()) { 
                            $ov = $dbModuleNo . "_" . $dbModuleName . "_" . $dbModuleId; 
                            if($ov == $_POST["module"]) 
                                echo "<option selected='true' value='$ov'>$dbModuleNo - $dbModuleName</option>" . PHP_EOL; 
                            else 
                                echo "<option value='$ov'>$dbModuleNo - $dbModuleName</option>" . PHP_EOL;
                         } 
                        ?>
                    </select>
                    <input id="moduleSubmit" type="submit" value="Submit Module" name="moduleSubmit" />
                </form>
        <?php if(isset($_POST["module"]) && $_POST["module"] != "") { ?>
                <form action="" method="post"> 
                    <p>
                    <strong>Selected Module:</strong><?php $dbModuleNo;?> - <?php$dbModuleName;?> <input type='hidden' value='<?php$_POST["module"];?>'>
                    </p>
                    Asessments: 
                    <?php
                    /*
                    $sessionquery = "
                        SELECT s.SessionId, SessionName, SessionDate, SessionTime, ModuleId, SessionActive, Complete
                        FROM Session s
                        INNER JOIN Session_Complete sc ON sc.SessionId = s.SessionId
                        WHERE
                        (ModuleId = ? AND SessionActive = ? AND Complete = ?)
                        ORDER BY SessionName 
                        ";
                    $active = 1;
                    $complete = 1;
                    $sessionqrystmt=$mysqli->prepare($sessionquery);
                    // You only need to call bind_param once
                    $sessionqrystmt->bind_param("iii",$moduleId, $active, $complete);
                    // get result and assign variables (prefix with db)
                    $sessionqrystmt->execute(); 
                    $sessionqrystmt->bind_result($dbSessionId,$dbSessionName,$dbSessionDate,$dbSessionTime, $dbModuleId, $dbSessionActive, $dbComplete);
                    $sessionqrystmt->store_result();
                    $sessionnum = $sessionqrystmt->num_rows();        
                    */
    
                if ($sessionnum == 0 ){    ?>
                    <span class='red'>Sorry, You have No Assessments under this Module</span>
                <?php } else { ?>
                    <select name="session" id="sessionsDrop">
                        <option value="">Please Select</option>
                        <?php
                            while ( $sessionqrystmt->fetch() ) {
                                $sv = $dbSessionId;
                                if($sv == $_POST["session"]) 
                                    echo "<option selected='true' value='$sv'>$dbSessionName - date('d-m-Y',strtotime($dbSessionDate)) - date('H:i',strtotime($dbSessionTime))</option>" . PHP_EOL;
                                else
                                    echo "<option value='$sv'>$dbSessionName - date('d-m-Y',strtotime($dbSessionDate)) - date('H:i',strtotime($dbSessionTime))</option>" . PHP_EOL;
                            }
                        ?>
                    </select>
                    <br>
                    <input type="submit" value="Submit Assigments">
                </form>
                <br>
                <br>
                <?php
        if(isset($_POST["session"]) && $_POST["session"] != "")    {
    
        /*
                $sessiondetailsquery = "
                    SELECT s.SessionId, SessionName, SessionDate, SessionTime, SessionDuration, SessionWeight, TotalMarks, 
                    s.ModuleId, ModuleNo, ModuleName, s.Room, Building, Capacity, SessionActive, Complete, PenaltyEnabled, COUNT(PenaltyMarks)
                    FROM Module m
                    INNER JOIN Session s ON m.ModuleId = s.ModuleId
                    INNER JOIN Session_Complete sc ON sc.SessionId = s.SessionId
                    LEFT JOIN Room r ON s.Room = r.Room
                    LEFT JOIN Penalty p ON s.SessionId = p.SessionId
                    LEFT JOIN Penalty_Marks pm ON s.SessionId = pm.SessionId
                    WHERE
                    (s.SessionId = ?)";
                $active = 1;
                $complete = 1;
                $sessiondetailsqrystmt=$mysqli->prepare($sessiondetailsquery);
                // You only need to call bind_param once
                $sessiondetailsqrystmt->bind_param("i",$dbSessionId);
                // get result and assign variables (prefix with db)
                $sessiondetailsqrystmt->execute(); 
                $sessiondetailsqrystmt->bind_result($detailsSessionId,$detailsSessionName,$detailsSessionDate,$detailsSessionTime, $detailsSessionDuration, $detailsSessionWeight, 
                $detailsTotalMarks, $detailsModuleId, $detailsModuleNo, $detailsModuleName, $detailsRoom, $detailsBuilding, $dbCapacity, $detailsSessionActive, $detailsComplete, 
                $dbPenaltyEnabled, $dbCountPenalyMarks);?>
                */
                <h3>CHOSEN ASSESSMENT</h3>
                <input type='text' id='currentId' name='Idcurrent' readonly='readonly' value='$detailsSessionId' /></td> 
                <br>
                <strong>Assessment:</strong> <?php $detailsSessionName; ?>
        <?php } else { ?>
                <p><strong class='red'>Please Select an Assessment</strong></p>
        <?php } } } else { ?>
                <p><strong class='red'>Please Select a Module</strong></p>
        <?php } ?>
    

1 个答案:

答案 0 :(得分:1)

<strong>Selected Module:</strong> - <?php$dbModuleName;?> <input type='hidden' value='<?php$_POST["module"];?>'>

这是你的错误。如果您查看源代码,您会看到PHP代码正在打印,因为您没有正确地间隔它。试试这个

<strong>Selected Module:</strong> - <?php echo $dbModuleName;?> <input type='hidden' value='<?php echo $_POST["module"];?>'>

<?php$dbModuleName;?>应为<?php echo $dbModuleName;?>