有下拉菜单和显示问题

时间:2016-11-23 20:10:12

标签: jquery html css mysql

我已经成功完成了这项任务,但是在获取第二个下拉框以显示mysql数据库所需的信息,然后将其与其他信息一起添加到数据库时遇到了问题。

错误:第二个下拉菜单将显示数据,但不会显示所选项目

注意:未定义的索引:第206行的C:\ xampp \ htdocs \ clock \ pages \ Work.php中的名称

警告:mysqli_fetch_array()要求参数1为mysqli_result,布尔值在第221行的C:\ xampp \ htdocs \ clock \ pages \ Work.php中给出

以下是代码:

<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

<title>Jobs Plus Door Clock</title>

<!-- Bootstrap Core CSS -->
<link href="../vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

<!-- MetisMenu CSS -->
<link href="../vendor/metisMenu/metisMenu.min.css" rel="stylesheet">

<!-- Custom CSS -->
<link href="../dist/css/sb-admin-2.css" rel="stylesheet">

<!-- Morris Charts CSS -->
<link href="../vendor/morrisjs/morris.css" rel="stylesheet">

<!-- Custom Fonts -->
<link href="../vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

<style type="text/css">
    .aah {
        color: white
    }

    .aah:hover {
        color: white
    }
</style>

</head>

<body>
<body style="overflow:auto;">

<div id="wrapper">

<div class="navbar-default " role="navigation">
    <div class="container-fluid">
        <ul class="nav navbar-nav" id="side-menu">

            <li>
                <a href="index.php"><i class="fa fa-dashboard fa-fw"></i> Door Clock </a>
            </li>
            <li>
                <a href="Work.php"><i class="fa fa-hourglass fa-fw"></i> Work Clock</a>
            </li>
            <li>
                <a href="#"><i class="fa fa-wrench fa-fw"></i>Manage Employees<span class="fa arrow"></span></a>
                <ul class="nav nav-second-level">
                    <li>
                        <a href="add.php">Add Employee</a>
                    </li>
                    <li>
                        <a href="employees.php">Employees</a>
                    </li>


                </ul>
                <!-- /.nav-second-level -->
            </li>
            auto
            <li>
                <a href=""><i class="fa fa-hourglass fa-fw"></i> Back To Job Time</a>
            </li>
            <li>
                <a href="time.php"><i class="fa fa-hourglass fa-fw"></i> Hours Worked</a>
            </li>
            <li>
                <a href="export.php">Export</a>
            </li>


        </ul>
    </div>
    <!-- /.sidebar-collapse -->
</div>
<!-- /.navbar-static-side -->


<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h3 class="page-header">Dashboard (TODAY) <?= date("Y-m-d") ?></h3>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="col-md-12 col-sm-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="row">
                        <?php
                        if (isset($_POST[ 'add' ])) {
                            include_once 'dbconnect.php';
                            $id = $_POST[ 'employee' ];
                            if (mysqli_query($con, "INSERT INTO `timing` (`employee_id`,start,date) VALUES "
                                . "(" . $id . ",NOW(),CURDATE())")) {
                                echo '<div class="alert alert-success">
                            Time Added
                        </div>';
                            } else {
                                echo '<div class="alert alert-danger">
                            Error while adding
                        </div>';
                            }
                        }


                        if (isset($_POST[ 'end' ])) {
                            include_once 'dbconnect.php';
                            $id = $_POST[ 'id' ];
                            if (mysqli_query($con, "UPDATE  `timing` set end=NOW() where id=" . $id)) {
                                echo '<div class="alert alert-success">
                            Time Stopped
                        </div>';
                            } else {
                                echo '<div class="alert alert-danger">
                            Error while stopping
                        </div>';
                            }
                        }

                        ?>
                        <form method="post">
                            <div class="col-xs-6">
                                <label>
                                    <select name="employee" class="form-control">
                                        <?php
                                    include_once 'dbconnect.php';
                                    $result2 = mysqli_query($con, "SELECT * from employees ORDER BY name ");
                                    while ($row2 = mysqli_fetch_array($result2)) {
                                        $name = $row2[ 'name' ];
                                        $id = $row2[ 'id' ];
                                        echo '<option value="' . $id . '">' . $name . '</option>';
                                        }

                                        ?>

                                    </select>
                                </label>
                            </div>
                            <div class="col-xs-6">

                                <form method="post">
                                    <div class="col-xs-6">
                                        <label>
                                            <select name="code_id" class="form-control">
                                                <?php
                                            include_once 'dbconnect.php';
                                            $result3 = mysqli_query($con, "SELECT * from codetiming  ");
                                            while ($row2 = mysqli_fetch_array($result3)) {
                                                $name1 = $row2[ 'name' ];
                                                $id = $row2[ 'id' ];
                                                echo '<option value="' . $id . '">' . $name1 . '</option>';
                                                }

                                                ?>

                                            </select>
                                        </label>
                                    </div>
                                    <div class="col-xs-6">


                                        <input class="btn btn-primary" type="submit" name="add" value="Set Time"/>
                                        <label>
                                            <input class="btn btn-primary" type=name="add" value="Clock All Out"/>
                                        </label>


                                    </div>
                                </form>

                            </div>
                    </div>

                </div>
            </div>

            <?php


            $result = mysqli_query($con, "SELECT *,TIMESTAMPDIFF(HOUR, start, end) 
       as `difference` from timing where date = CURDATE()");
            while ($row = mysqli_fetch_array($result)) {
                $empolyee_id = $row[ 'employee_id' ];
                $id = $row[ 'id' ];
                $start = date_create($row[ 'start' ]);
                $start = date_format($start, "Y-m-d h:i:s A");
                $code_id = $row[ 'name1' ];


                if (!empty($row[ 'end' ])) {
                    $end = date_create($row[ 'end' ]);
                    $end = date_format($end, "Y-m-d h:i:s A");
                } else {
                    $end = $row[ 'end' ];
                }

                $result2 = mysqli_query($con, "SELECT * from employees where id=" . $empolyee_id);
                $row2 = mysqli_fetch_array($result2);
                $name = $row2[ 'name' ];

                $result2 = mysqli_query($con, "SELECT * from codetiming where id=" . $code_id);
                $row2 = mysqli_fetch_array($result2);
                $name1 = $row2[ 'name1' ];
                echo '<center><h4><b><h1 style="font-size:200%;">' . $name . '</h1></b></h4></center><hr/>';
                echo '<div class="col-lg-6 col-md-6">
                <div class="panel panel-success">
                    <div class="panel-heading">
                        <div class="row">
                            <div class="col-md-12">
                                <center><h2>' . $start . ' (' . $name1 . ')</h2></center>
                                </div>

                        </div>
                    </div>

                </div>
            </div>';

                if (!empty($end)) {
                    echo '<div class="col-lg-6 col-md-6">
                <div class="panel panel-success">
                    <div class="panel-heading">
                        <div class="row">
                            <div class="col-md-12">
                                <center><h2>' . $end . ' (' . $name1 . ')</h2></center>
                                </div>

                        </div>
                    </div>

                </div>
            </div>';
                } else {
                    echo '<div class="col-lg-6 col-md-6">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <div class="row">
                            <div class="col-xs-12">
                                <center><h2><form method="post"><input type="submit" name="end" value="OUT" /><input type="hidden" name="id" value="' . $id . '"/></form></h2></center>
                                </div>

                        </div>
                    </div>

                </div>
            </div>';
                }
            }
            ?>


        </div>

        <!-- /.row -->
    </div>
    <!-- /#page-wrapper -->

</div>
<!-- /#wrapper -->

<!-- jQuery -->
<script src="../vendor/jquery/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="../vendor/bootstrap/js/bootstrap.min.js"></script>

<!-- Metis Menu Plugin JavaScript -->
<script src="../vendor/metisMenu/metisMenu.min.js"></script>

<!-- Morris Charts JavaScript -->
<script src="../vendor/raphael/raphael.min.js"></script>
<script src="../vendor/morrisjs/morris.min.js"></script>
<script src="../data/morris-data.js"></script>

<!-- Custom Theme JavaScript -->
<script src="../dist/js/sb-admin-2.js"></script>

我已设法获取名称并开始工作时间和结束时间和日期并进入数据库,但是第二个下拉菜单显示和添加所需信息时出现问题。

1 个答案:

答案 0 :(得分:0)

可能是您的查询失败或返回错误。您想使用mysqli_error()来查看实际发生的情况。将以下代码放入检查:

if (!$result2) {
    printf("Error: ", mysqli_error($con));
    exit();
}