为什么$ _POST和$ _GET在这种形式下工作?

时间:2018-03-24 07:50:11

标签: php html post mysqli get

我正在练习PHP和MySQLi y创建课堂辅助系统(检查学生和教室的帮助)。但是,我似乎陷入了一个问题......

我想做的很简单:教师输入他们拥有的四位数代码(保存在数据库中)进行登录。他们的代码发布到页面uad_asist_class.php,此页面将在数据库中执行查询,显示教师的简单问候名称(数据库中的所有信息)。

示例:教师输入代码:5690,页面显示"布宜诺斯艾利斯,Pedro Romo"

问题是$_GET$_POST都没有将代码发送到页面(我检查了POST数组并且它是空的)。我想知道我做错了什么。 (请随意将我的代码翻译成新代码,以便进行练习。)

以下是代码:

index.php:这家伙发送老师输入的代码

<!DOCTYPE html>
<html>
  <!--
        Load the page to adapt to the viewport on any devices
    -->
    <meta 
        name = "viewport" 
        content = "width = device-width, initial-scale = 1.0">

        <head>
            <!--
                Load script file
                Loads the functions for this page
            -->
            <script 
                type = "text/javascript" 
                src = "../js/UAD-password-login.js?v=1.8">
            </script>

            <!--
                Load the stylesheet
                This stylesheet contains:
                >> Buttons styling
                >> Paragraphs and text styling
                >> Custom formularies
            -->
            <link
                rel = "stylesheet"
                type = "text/css"
                href = "../css/UAD-main-style.css?v=2.3">

            <!--
                Page title on Chrome, Firefox tabs
            -->
            <title>
                Inicio de sesión
            </title>
        </head>

         <!--
            The page performs the function RealTimeClock
            This function is defined on file "UAD-realtime-clock.js"            
         -->
        <body onload = "RealTimeClock()">
            <!--
                Page main heading 
            -->
            <center>

                <!--
                    This heading shows the title of the page
                    This heading uses the style "uad_heading_01"
                -->
                <h1
                    id = "uad_heading_01"
                    align = "center"
                    style = "font-size:56px">
                    Inicio de sesión
                </h1>
            </center>

            <center>

                <!--
                    A subtitle, indicating the user what to do
                -->
                <p
                    class = "uad_text"
                    align = "center"
                    style = "font-size:24px">       
                    Introduzca su clave de profesor para iniciar sesión...
                </p>
            </center>

            <br>

            <!--
                Formulary inputs
            -->
            <form 
                action = "/uad_asist_class.php" 
                method = "post">
                <!--
                    This class denotes a row, grouping divs in a horizontal line
                -->
                <div
                    class = "row">

                    <!--
                        This class denotes a column
                        A group of elements vertically aligned 
                    -->
                    <div
                        class = "col"
                        align = "center">

                        <!--
                            Password bar
                            Password is captured here by the number buttons
                        -->
                        <input
                            id = "prof_password"
                            name = "clave"
                            class = "uad_password_input"
                            type = "text"
                            required
                            disabled = "disabled"
                            placeholder = "Clave..."
                            maxlength = "4">

                        <br><br>

                        <!--
                            Log In button
                            After inserting a password, log in with the teacher username
                        -->
                        <input
                            class = "uad_form_button"
                            type = "submit"
                            value = "I N I C I A R">

                        <!--
                            Eye button
                            Serves to show or hide the password
                        -->
                        <input
                            class = "uad_eyeicon_button"
                            onclick = "HideShowPassword()"
                            type = "button">

                    </div>

                    <br><br>

                    <!--
                        This class denotes a column
                        A group of elements vertically aligned 
                    -->
                    <div
                        class = "col"
                        align = "center">

                        <!--
                            Number 1 button
                        -->
                        <input
                            class = "uad_num_button"
                            type = "button"
                            onclick = "InsertPassword('1')"
                            value = "1">            

                        <!--
                            Number 2 button
                        -->
                        <input
                            class = "uad_num_button"
                            type = "button"
                            onclick = "InsertPassword('2')"
                            value = "2">

                        <!--
                            Number 3 button
                        -->
                        <input
                            class = "uad_num_button"
                            type = "button"
                            onclick = "InsertPassword('3')"
                            value = "3">

                        <br>


                        <!--
                            Number 4 button
                        -->
                        <input
                            class = "uad_num_button"
                            type = "button"
                            onclick = "InsertPassword('4')"
                            value = "4">            

                        <!--
                            Number 5 button
                        -->
                        <input
                            class = "uad_num_button"
                            type = "button"
                            onclick = "InsertPassword('5')"
                            value = "5">

                        <!--
                            Number 6 button
                        -->
                        <input
                            class = "uad_num_button"
                            type = "button"
                            onclick = "InsertPassword('6')"
                            value = "6">

                        <br>


                        <!--
                            Number 7 button
                        -->
                        <input
                            class = "uad_num_button"
                            type = "button"
                            onclick = "InsertPassword('7')"
                            value = "7">            

                        <!--
                            Number 8 button
                        -->
                        <input
                            class = "uad_num_button"
                            type = "button"
                            onclick = "InsertPassword('8')"
                            value = "8">

                        <!--
                            Number 9 button
                        -->
                        <input
                            class = "uad_num_button"
                            type = "button"
                            onclick = "InsertPassword('9')"
                            value = "9">

                        <br>


                        <!--
                            Backspace button
                        -->
                        <input
                            class = "uad_del_button"
                            type = "button"
                            onclick = "ErasePassword()"
                            value = "<">
                        <!-- &#8592; -->

                        <!--
                            Number 0 button
                        -->
                        <input
                            class = "uad_num_button"
                            type = "button"
                            onclick = "InsertPassword('0')"
                            value = "0">

                        <!--
                            Clear password input button
                        -->
                        <input
                            class = "uad_clear_button"
                            type = "button"
                            onclick = "ClearPassword()"
                            value = "C">
                    </div>
                </div>
            </form>

            <br>

            <!--
                Real-time clock
                Shows a real time clock on screen
            -->
            <div
                class = "uad_text"
                id = "realTimeClock"
                align = "center"
                style = "font-size:76px">
            </div>

            <br>

            <!--
                Real-time Date
                Shows today's date in a format
            -->
            <div
                class = "uad_text"
                id = "todayDate"
                align = "center"
                style = "font-size:32px">
            </div>

            <!--
                Footer of the page
                Shows the information of the school, and the year of development
            -->
            <div
                class = "uad_footer">
                Universidad de Artes Digitales &copy 2018 - Guadalajara, Jalisco, M&eacutexico
            </div>
        </body>
</html>

uad_asist_class.php:这家伙收到老师输入的代码,根据输入显示信息

    <!--------------------------------------------------------------------------------------------------

    uad_asist_class.html

    This is the main page to capture students assistance in class.
    Here, a teacher has logged in and starts capturing assistance by pressing buttons with the students' names. A buttons press adds a "NOT PRESENT" to that class block for the day, adding new absences after every class block.

Class blocks are intervals of 50 min for classes. There can be up to four blocks of that class per day, and only four blocks can exist weekly.

--------------------------------------------------------------------------------------------------->
<!DOCTYPE html>
<html>

    <!--
        Load the character set
    -->
    <meta
        charset = "UTF-8">

        <!--
            Page head
        -->
        <head>

            <!--
                Load the JavaScript script
                - Functions to show 
            -->
            <script
                type = "text/javascript"
                src = "../js/UAD-capture-assistance.js?v=1.7">
            </script>

            <!--
                Load this page's stylesheet
            -->
            <link
                rel = "stylesheet"
                type = "text/css"
                href = "../css/UAD-assisthub-style.css?v=3.1">

            <!--
                Load the main stylesheet
            -->
            <link
                rel = "stylesheet"
                type = "text/css"
                href = "../css/UAD-main-style.css?v=2.4">

            <!--
                Page title
                Title for the tabs
            -->
            <title>
                Toma de asistencias
            </title>
        </head>

        <!--
            Body of the page 
        -->
        <body onload = "AssistMain()">

            <div>

                <!--
                    1st row: 
                -->
                <div
                    class = "row">

                    <!--
                        1st column:
                    -->
                    <div
                        class = "col"
                        align = "center">

                        <!--
                            Display the university's logo
                            Check path "../Intranet_UAD/media/image/" for logo
                        -->
                        <img
                            src = "../media/image/uad_logo.png"
                            align = "center"
                            width = "413px"
                            height = "auto">
                    </div>

                    <!--
                        2nd column: WELCOME TO THE USER
                        Display a greeting message to the teacher.
                        Values change depending on the user who logged in
                    -->
                    <div
                        class = "col"
                        align = "center">

                        <!--
                            Display a simple greeting to the user
                        -->
                        <h1
                            id = "uad_heading_01"
                            align = "center"
                            style = "font-size:72px;">
                            ¡Buen dia!
                        </h1>

                        <!--
                            Display the user's name
                            Value changes depending on logged user
                        -->
                        <p
                            class = "uad_text"
                            align = "center"
                            style = "font-size:44px;">
                            <?php
                                if(isset($_POST["clave"]))
                                {   
                                    echo "La clave insertada es: " . $_POST["clave"];
                                }

                                else
                                {
                                    echo "Error!";
                                }
                                /*
                                $prof_clave = "";

                                $servername = "localhost";
                                $username = "root";
                                $password = "";
                                $dbname = "uad_personnel";

                                // Connection to database saved here
                                $connection = new mysqli($servername, $username, $password, $dbname);

                                //
                                if($connection->connect_errno)
                                {
                                    //
                                    die();
                                }

                                if($_SERVER["REQUEST_METHOD"] == "POST")
                                {
                                    $prof_clave = test_input($_POST['clave']);
                                }

                                function test_input($input)
                                {
                                    $input = trim($input);
                                    $input = stripslashes($input);
                                    $input = htmlspecialchars($input);

                                    return $input;
                                }

                                echo "La clave insertada es: " . $prof_clave;

                                $query = "SELECT nombre FROM profesores WHERE 'clave' LIKE '" . $prof_clave . "%'";

                                //
                                $result = $connection->query($query);

                                //
                                if ($result->num_rows > 0) 
                                {
                                    // output data of each row
                                    while($row = $result->fetch_assoc()) 
                                    {
                                        //
                                        echo $row['nombre'] . "<br>";
                                    }
                                } 

                                else 
                                {
                                    //
                                    echo "nombre no disponible";
                                }

                                //
                                $connection->close();
                                */
                            ?>

                        </p>
                    </div>

                    <!--
                        3rd column: CAREER LOGO
                        Show an image of the class' career.
                        Changes depending on the career the class belongs.

                        Values are:
                        - IDV : Ingenieria en Desarrollo de Videojuegos
                        - LDDA : Lic. en Diseño y Desarrollo de Aplicaciones
                        - LA : Lic. en Animación
                        - LPA : Lic. en Producción Audiovisual

                        Check path "../Intranet/media/image/" for the career logos
                    -->
                    <div
                        class = "col"
                        align = "center">
                        <!--
                            Display the university's logo
                            Check path "../Intranet_UAD/media/image/" for logo
                        -->
                        <img
                            src = "../media/image/idv_logo.png"
                            align = "center"
                            width = "auto"
                            height = "auto">
                    </div>
                </div>

                <!--
                    2nd row: INFO DISPLAY
                    - Class name. Info to display to teacher, changes depending on time.
                    - Date info. Display to user and used to insert data on ABSENCE table on database
                    - Student buttons. Click to set student as NOT PRESENT.
                    - Click again to unmark as NOT PRESENT.
                -->
                <div
                    class = "row">

                    <!--
                        1st column: CAPTURE ASSISTANCES
                        - Save the assistance data on the table.
                    -->
                    <div
                        class = "col"
                        align = "center">
                        <div
                            id = "ClockDisplay"
                            class = "uad_text"
                            align = "center"
                            style = "font-size: 48px;">
                        </div>

                        <br>

                        <div
                            id = "DateDisplay"
                            class = "uad_text"
                            align = "center"
                            style = "font-size: 24px"
                        >
                        </div>
                    </div>

                    <!--
                        2nd column: CAPTURE ASSISTANCES
                        - Save the assistance data on the table.
                    -->
                    <div
                        class = "col"
                        align = "center">
                        <div
                            class = "uad_text"
                            align = "center"
                            style = "font-size: 48px;">
                            Fundamentos de Fisica I
                        </div>  
                    </div>  
                </div>

                <br><br><br>

                <?php
                    // Here we control the buttons to get the information to present the pages
                    // Here we will...
                    /*
                        1- Load a new 
                    */
                ?>

                <!--
                    3rd row: INFO DISPLAY
                    - Class name. Info to display to teacher, changes depending on time.
                    - Date info. Display to user and used to insert data on ABSENCE table on database
                    - Student buttons. Click to set student as NOT PRESENT.
                    - Click again to unmark as NOT PRESENT.
                -->
                <div
                    class = "row">
                    <!--
                        1st column: CAPTURE ASSISTANCES
                        - Save the assistance data on the table.
                    -->
                    <div
                        class = "col"
                        align = "center">
                        <!--
                            1st column: CAPTURE ASSISTANCES
                            - Save the assistance data on the table.
                        -->
                        <input
                            class = "uad_long_button"
                            type = "button"
                            align = "center"
                            value = "Capturar">
                    </div>
                </div>

            </div>



            <!--
                Footer of the page
                Shows the information of the school, and the year of development
            -->
            <div
                class = "uad_footer">
                Universidad de Artes Digitales &copy 2018 - Guadalajara, Jalisco, México
            </div>
        </body>
</html>

另外,我正在使用XAMPP,phpmyadmin ver。 4.5.1使用默认用户和密码信息(无论我需要检查什么,还没有添加,请告诉我)

1 个答案:

答案 0 :(得分:0)

具有属性name的唯一输入字段是 clave 。但如果$_POST变量具有disabled="disabled"属性,则不会在readonly变量中发送,因为禁用的字段不会与表单提交一起传递。如果您希望该字段不可编辑,请将其设置为$_POST,您仍然可以使用ShippingStatus s(location, status, timeUpdated)变量获取该字段。