我正在学习PHP,现在我尝试制作简单的ShoutBox。 为什么ShoutBox不显示任何用户名,消息和错误消息?我在代码中的错误在哪里?
我的index.php:
<!-- INCLUDES -->
<?php include 'database.php'; ?>
<!-- Create select query -->
<?php
$query = "SELECT * FROM shouts";
$shouts = mysqli_query($con, $query);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>SHOUTBOX</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
<!-- MAIN CONTAINER -->
<div id="container">
<header>
<h1>SHOUT IT! Shoutbox</h1>
</header>
<!-- SHOUTS -->
<div id="shouts">
<ul>
<?php while($row = mysqli_fetch_assoc($shouts)) : ?>
<li class="shout"><span><?php echo $row['time'] ?> - </span><strong><?php echo $row['user'] ?></strong> : <?php echo $row['message'] ?></li>
<?php endwhile; ?>
</ul>
</div>
<!-- INPUT -->
<div id="input">
<?php if(isset($_GET['error'])) : ?>
<div class="error"> <?php echo $_GET['error']; ?> </div>
<?php endif; ?>
<form method="post" action="process.php">
<input type="text" name="user" placeholder="Your name" />
<input type="text" name="message" placeholder="Your message" />
</br >
<input class="shout-btn" type="submit" name="submit" value="Shout it out" />
</form>
</div>
</div>
</body>
</html>
我的process.php:
<?php
include 'database.php';
//Check if form submitted
if(isset($_POST['submit'])) {
$user = mysqli_real_escape_string($con, $_POST['user']);
$message = mysqli_real_escape_string($con, $_POST['message']);
//Set timezone
date_default_timezone_set('America/New_York');
$time = date('h:i:s a',time());
//Validate input
if(!isset($user) || $user = '' || !isset($message) || $message = '') {
$error = "Please fill in your name and a message";
header("Location: index.php?error=".urlencode($error));
exit();
} else {
$query = "INSERT INTO shouts (user, message, time)
VALUES ('$user','$message','$time')";
if(!mysqli_query($con, $query)) {
die('Error: '.mysqli_error($con));
} else {
header("Location: index.php");
exit();
}
}
}
MySQL数据库正在运作。
答案 0 :(得分:1)
第14行应该读......
//app.js
(function() {
angular.module('app', [])
.controller('myController', function($scope) {
$scope.foo = 'World!';
}
})();
记住==然后语句变为“if”user为空/ null“或”message is empty / null post post“请填写你的姓名和留言”