使用PHP白屏显示更新数据库

时间:2017-09-05 17:58:46

标签: php

我一直致力于一个项目,我正处于项目的最后阶段。我的问题是每当我尝试更新数据库表中的数据时返回一个没有错误消息的空白屏幕。请在下面找到php脚本和html表单(负责更新数据库表的表单),我已将其划分

<?php
Session_start();
if(!isset($_SESSION['username'])){
header('Location: login.php');
}
?>


<!DOCTYPE html>
<html lang="en">
    <head>
        <?php include('config/mm.php')?>
        <?php include('config/db.php')?>
        <?php include('config/function.php')?>
        <?php include('config/setup.php')?>
        <?php include('config/head.php')?>


    <?php
    mysqli_set_charset ($dbc,'utf8');
    if(isset($_GET['edit'])) {

        $edit_id = $_GET['edit'];

        $edit_query = "select * from contact where id='$edit_id'";

        $run_edit = mysqli_query($dbc, $edit_query); 

        while ($edit_row = mysqli_fetch_array($run_edit)){


            $id = $edit_row['id'];
            $title = $edit_row['title'];
            $header = $edit_row['header'];
            $header1 = $edit_row['header1'];
            $body = $edit_row['body'];
            $body1 = $edit_row['body1'];
            $body2 = $edit_row['body2'];
            $body3 = $edit_row['body3'];
            $body4 = $edit_row['body4'];
            $body5 = $edit_row['body5'];
    }
    }
    ?>


</head>
<body class="nav-md">
    <!-- Side Nav Bar -->
    <div class="container body">
        <?php include('config/sidenav.php')?>
    </div>
    <!-- top navigation -->
    <?php include('config/topnav.php')?>
    <!-- /top navigation -->

    <!-- page content -->
    <div class="right_col" role="main">
        <div class="container">
        <form action="updatecontactus.php?edit_form=<?php echo $id; ?>" method="post" enctype="multipart/form-data">
          <h2>Table</h2>                                                                                      
          <div class="table table-bordered table-responsive">          
          <table class="table">
            <thead>
              <tr>
                <th>#</th>
                <th>Name</th>
                <th>Content</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>3</td>
                <td>header</td>
                <td><textarea class="form-control" type="text" name="header" rows="2"><?php echo $header; ?></textarea></td>
              </tr>
              <tr>
                <td>4</td>
                <td>header1</td>
                <td><textarea class="form-control" type="text" name="header1" rows="2"><?php echo $header1; ?></textarea></td>
              </tr>
              <tr>
                <td>5</td>
                <td>body</td>
                <td><textarea class="form-control" type="text" name="body" rows="2"><?php echo $body; ?></textarea></td>
              </tr>
              <tr>
                <td>6</td>
                <td>body1</td>
                <td><textarea class="form-control" type="text" name="body1" rows="2"><?php echo $body1; ?></textarea></td>
              </tr>
              <tr>
                <td>7</td>
                <td>body2</td>
                <td><textarea class="form-control" type="text" name="body2" rows="2"><?php echo $body2; ?></textarea></td>
              </tr>
              <tr>
                <td>8</td>
                <td>body3</td>
                <td><textarea class="form-control" type="text" name="body3" rows="2"><?php echo $body3; ?></textarea></td>
              </tr>
              <tr>
                <td>9</td>
                <td>body4</td>
                <td><textarea class="form-control" type="text" name="body4" rows="2"><?php echo $body4; ?></textarea></td>
              </tr>
              <tr>
                <td>10</td>
                <td>body5</td>
                <td><textarea class="form-control" type="text" name="body5" rows="2"><?php echo $body5; ?></textarea></td>
              </tr>
              <tr>
                    <td align="center" colspan="6"><input type="submit" name="update" value="Update Now"></td>
                </tr>
            </tbody>
          </table>
          </div>
          </form>
        </div>
    </div>  

    <!-- /page content -->

    <!-- footer content -->
    <?php include('config/footer.php')?>
    <!-- /footer content -->
    </div>  
    </div>          
    <!-- jQuery -->
    <script src="vendors/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="vendors/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="vendors/fastclick/lib/fastclick.js"></script>
    <!-- NProgress -->
    <script src="vendors/nprogress/nprogress.js"></script>
    <!-- bootstrap-wysiwyg -->
    <script src="vendors/bootstrap-wysiwyg/js/bootstrap-wysiwyg.min.js"></script>
    <script src="vendors/jquery.hotkeys/jquery.hotkeys.js"></script>
    <script src="vendors/google-code-prettify/src/prettify.js"></script>

    <!-- Custom Theme Scripts -->
    <script src="build/js/custom.min.js"></script>
</body>

更新代码:

<?php

        include("config/db.php");
        mysqli_set_charset ($dbc,'utf8');
            if(isset($_POST['update'])){

            $update_id = $_GET['edit_form'];


            $header = $_POST['header'];
            $header1 = $_POST['header1'];
            $body = $_POST['body'];
            $body1 = $_POST['body1'];
            $body2 = $_POST['body2'];
            $body3 = $_POST['body3'];
            $body4 = $_POST['body4'];
            $body5 = $_POST['body5'];

            if($header=='' or $header1=='' or $body=='' or $body1=='' or $body2=='' or $body3=='' or $body4=='' or $body5==''

            )
            {

            echo "<script>alert('Any of the fields is empty')</script>";
            exit();
            }

            else {

                $update_query = "update contact set header='$header',header1='$header1', body='$body', body1='$body1', body2='$body2', body3='$body3', body4='$body4', body5='$body5' where id='$update_id'";

                if(mysqli_query($dbc, $update_query)){

                echo "<script>alert('Post has been updated')</script>";

                echo "<script>window.open('contactus.php','_self')</script>";

                }

            }
            }



        ?>

0 个答案:

没有答案