如何从$ getname中获取值到出勤表

时间:2018-08-05 16:09:17

标签: php html

如何从$getname(第一个代码)获取价值并将其插入到出勤表(第二个代码)

<?php
    $getid = $_GET['receiptv'];
    $getname = $_GET['rid'];  <<<<<<<<<<<<<<<<< this value
    ?>

<!DOCTYPE html>
<html lang = "eng">
<head>
    <meta charset = "utf-8" />
    <title>SAMS</title>
    <meta name = "viewport" content = "width=device-width, initial-scale=1" />
    <link rel = "stylesheet" type = "text/css" href = "css/bootstrap.css"/>
</head>
<body class = "alert-info">

    <div class = "container-fluid">
        <h2 class="form-signin-heading">Activity ID  
            <?php echo $getid ?> Activity Name  <?php echo $getname ?> </h2><hr/>

        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <div class = "col-lg-3"></div>
        <div class = "col-lg-6 well">
            <h2>Attendance Login</h2>
            <br />
            <div id = "result"></div>
            <br />
            <br />
            <form enctype = "multipart/form-data">
                <div class = "form-group">
                    <label>Student ID:</label>
                    <input type = "text" id = "student" class = "form-control" required = "required"/>
                    <br />
                    <br />
                    <div id = "error"></div>
                    <br />
                    <button type = "button" id = "login" class = "btn btn-primary btn-block"><span class = "glyphicon glyphicon-login"></span>Login</button>
                </div>
            </form>
        </div>
    </div>
</body>
<script src = "js/jquery.js"></script>
<script src = "js/bootstrap.js"></script>
<script src = "js/login.js"></script>
</html>

第二个代码

<?php
require_once 'connect.php';
$student = $_POST['student'];
$attendance = date("H:i", strtotime("+6 HOURS"));
$date = date("Y-m-d", strtotime("+6 HOURS"));
$q_student = $conn->query("SELECT * FROM `student` WHERE `ID` = '$student'") or die(mysqli_error());
$f_student = $q_student->fetch_array();
$student_name = $f_student['Name'];
$getname = $_GET['rid']; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$conn->query("INSERT INTO attendance VALUES('', '$student', '$student_name', '$attendance', '$date','$getname <<<<<<<<<<<<<<<<')") or die(mysqli_error());
echo "<h3 class = 'text-muted'>".$student_name." <label class = 'text-info'>at  ".date("h:i a", strtotime($attendance))."</label></h3>";

第三个代码

<?php
require_once 'connect.php';
$student = $_POST['student'];
$q_student = $conn->query("SELECT * FROM `student` WHERE `ID` = '$student'") or die(mysqli_error());
$v_student = $q_student->num_rows;
if($v_student > 0){
    echo 'Success';
}else{
    echo 'Error';
}

---------------------------------------------------------

$(document).ready(function(){
$error = $('<center><h2 class = "text-danger">You are not a student here...<h2></center>');
$error1 = $('<center><h2 class = "text-danger">Please fill up the field<h2></center>');
$('#login').click(function(){
    $error.remove();
    $error1.remove();
    $student = $('#student').val();
    if($student == ""){
        $error1.appendTo('#error');
    }else{  
        $.post('check.php', {student: $student},
            function(show){
                if(show == 'Success'){
                    $.ajax({
                        type: 'POST',
                        url: 'login.php',
                        data: {
                            student: $student
                        },
                        success: function(result){
                            $result = $('<h2 class = "text-warning">You have been login:</h2>' + result).appendTo('#result');
                            $('#student').val('');
                            setTimeout(function(){
                                $result.remove();
                            }, 10000);
                        }
                    });
                }else{
                    $('#student').val('');
                    $error.appendTo('#error');
                }
            }
        )
    }   
  });
});

1 个答案:

答案 0 :(得分:1)

这可以通过两种方式来完成。使用这样的PHP会话。 在代码1中

$_SESSION['getname'] = $getname

并在代码2中将其用作

$_SESSION['getname'];
unset($_SESSION['getname'];

如果您不再使用它,则可以取消设置。

或使用隐藏的表单元素

<input type="hidden" name="getname" value="<?= $getname ?>">

您可以像过去使用form一样,以代码2的形式访问它。