php - echo 不显示,或添加ID,但在数据库中显示

标签 php mysql database

我设置了一个在本地服务器上完美运行的 PHP 数据库。然后,当我通过我的托管站点 Site5 将其放到网上时,我收到了此类错误:“无法修改 header 信息 – header 已由...发送”。因此,我更改了 Site5 上的 PHP 文件以打开输出缓冲。现在,我没有收到错误,但是,每当我输入数据时,它都不会回显 - 但是,它确实显示在 phpMyAdmin 的数据库中(但没有 ID)。

关于为什么它没有回显以及为什么它的新数据没有获得 ID 有什么想法吗?

这里是事件的(和损坏的): http://hjaramillo.com/tell_me/index.php

<!DOCTYPE html>
<html class="no-js" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>A Message For You</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="css/media.css" rel="stylesheet">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
</head>
<?php 
 ob_start();
 //error_reporting(0);
 require 'db/connect.php'; 
 require 'functions/security.php';
 error_reporting(E_ALL);

 $records = array();

 if(!empty($_POST)){


 if(isset($_POST['first_name'],$_POST['location'],$_POST['message'])) {

$first_name = trim($_POST['first_name']);
$location   = trim($_POST['location']);
$message    = trim($_POST['message']);

if(!empty($first_name) && !empty($location) && !empty($message)) {
  $insert = $db -> prepare("INSERT INTO message (first_name, location, message, date) VALUES (?,?,?,NOW())");
  $insert->bind_param('sss',$first_name,$location,$message);

  if($insert -> execute()){
    header ('Location: index.php');
    die();
  }
}

 }
}
if($results = $db->query("SELECT * FROM message ORDER BY id DESC LIMIT 1")) {
if($results->num_rows) {
  while($row = $results->fetch_object()) {
    $records[] = $row;
   }
   $results -> free();
 }
}

?>
<?php
  if (!count($records)){
    echo 'No messages';
  } else{

?>
  <?php
  foreach($records as $r){
  ?>

<body>
  <?php
  }}
?>
<div class="form-show">
  <div class="post-icon">
    <a href="#"><img src="images/post_icon.png"/></a>
  </div>
</div>
<div class="form-background">
<div class="form-container">
<div class="form-title">
   <p>Tell someone that:</p>
</div>
<form action="index.php" method="post">
      <div class="fields msg">
        <!--<label for="message">Message</label>-->
        <textarea name="message" id="message" autocomplete="off"></textarea>
      </div>
      <div class="fields">
      <ul>
        <li> <label for="first_name">Name</label> </li>
        <li> <input type="text" class="s-input" name="first_name" id="first_name" autocomplete="off"> </li>
      </ul>
      </div>
      <div class="fields last">
        <ul>
          <li><label for="location">Location</label></li>
          <li><input type="text" class="s-input" name="location" id="location" autocomplete="off"></li>
        </ul>
      </div>
      <input type="submit" value="Post" id="submit-button">
   </form>
  <div>
</div>
</div>
</div>

<div class="msg-container">
 <div class="msg-intro">
  <p> On <?php echo escape($r->date); ?>,</p>
  <p><span style="text-transform:capitalize;"><?php echo escape($r->first_name); ?>            </span> from 
 <span style="text-transform:capitalize;"><?php echo escape($r->location); ?></span>   wanted to tell you:</p>
  </div>
  <div class="msg-content">
    <p><?php echo escape($r->message); ?></p>
  </div>
 </div>


</body>
<script type="text/javascript" src="js/application.js"></script>
</html>

最佳答案

之前有人问我的 ID 是否设置为自动增量 - 事实并非如此。这就是问题所在,谢谢!

关于php - echo 不显示,或添加ID,但在数据库中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20733146/

相关文章:

mysql - 用于每日报告的php mysql命令

sql - SQL中的一个思想实验

sql - 使用多个模式进行查询 - Dbeaver

php - 由于/tmp 充满了 PHP session 文件,mySQL 崩溃了..怎么办?

php - 使用 PHP Html5 流式传输视频

python - orm ['model' ].objects.create(attr=some_value) 导致 IntegrityError

mysql - 远程数据库访问(从 Parallels 电源面板)

php - 如何获取 SELECT OPTION 的选定值

php - 我从 Utf-8 mysql 表中获取 Ansi 字符串而不是 Utf-8

MySQL 字母数字列上的 MIN 和 MAX