PHP的会话消息麻烦

时间:2018-10-19 21:28:15

标签: php web-hosting

我试图在000webhosting.com上建立一个在线网站,并与数据库完美连接。现在我放入session_start();在php标记后的第一行。我不知道自己做错了什么,但是出现了这个提示。

enter image description here

这是我的process.php,其中存在我的session_start()代码

<?php
    session_start();
    $mysqli = new mysqli('localhost','id7527472_root','123123123as','id7527472_testingweebo') or die(mysqli_error($mysqli));
    if(isset($_POST['save'])){
        $name = $_POST['name'];
        $location = $_POST['location'];
        $mysqli->query("INSERT INTO sampledata (name, location) values ('$name', '$location')") or die($mysqli->error);
        $_SESSION['message'] = "Record Saved!";
        $_SESSION['msg_type'] = "success";  
        header("location: test.php");
    }
    if(isset($_GET['delete'])){
        $id = $_GET['delete'];
        $mysqli->query("DELETE FROM sampledata WHERE id=$id") or die($mysqli->error());
        $_SESSION['message'] = "Record Deleted!";
        $_SESSION['msg_type'] = "danger";
        header("location: test.php");
    }
?>

我尝试搜索,这导致我将其编码为没有BOM的UTF8。在记事本++上进行了尝试,然后上传了,但仍然无法正常工作。

编辑

这是我的test.php文件,它在会话开始时调用process.php。

<html>
    <head>
        <title>testinglangPar</title>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
    </head>
    <body>
        <?php require_once 'process.php'; ?>
        <?php 
        if (isset($_SESSION['message'])):?>
        <div class="alert alert-<?=$_SESSION['msg_type']?>">
            <?php 
                echo $_SESSION['message'];
                unset ($_SESSION['message']);?>
        </div>
        <?php endif ?>

        <div class="container">
        <?php
    $mysqli = new mysqli('localhost','id7527472_root','123123123as','id7527472_testingweebo') or die(mysqli_error($mysqli));
        $result = $mysqli->query("SELECT * FROM sampledata") or die($mysqli->error);
        ?>

        <div class="row justify-content-center">
            <table class="table">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Location</th>
                        <th colspan="2">Action</th>
                    </tr>
                </thead>
                <?php   
                    while($row = $result->fetch_assoc()): ?>
                    <tr>
                        <td><?php echo $row['name'] ?></td>
                        <td><?php echo $row['location'] ?></td>
                        <td>
                            <a href="test.php?edit=<?php echo $row['id']; ?>"
                                class="btn btn-info">Edit</a>
                            <a href="process.php?delete=<?php echo $row['id']; ?>"
                                class="btn btn-danger">Delete</a>    
                        </td>
                    </tr>
                    <?php endwhile; ?>
              </table>  
        </div>
        <?php 
                function pre_r($array){
                    echo '<pre>';
                    print_r($array);
                    echo '</pre>';
                }
                ?>


        <div class="row justify-content-center">
        <form action="process.php" method="POST">
            <div class="form-group">
            <label>Name</label>
            <input type="text" name="name" class="form-control" placeholder="Enter your name">
            </div>
            <div class="form-group">
            <label>Location</label>
            <input type="text" name="location" class="form-control" placeholder="Enter your location">
            </div>
            <div class="form-group">
            <button type="submit" class="btn btn-primary" name="save">Save</button>
            </div>
        </form>
        </div>
        </div>
    </body>
</html>

1 个答案:

答案 0 :(得分:1)

此错误是由于控制台上的某些输出所致。在代码行中看到,您可能有一些空格,或者在会话启动后尝试使用ob_start(),这样它将使用输出缓冲区。您可以找出有问题的代码部分