我尝试使用标题,但收到了此警告:
警告:无法修改标头信息 - 已发送的标头 (输出始于 /Applications/XAMPP/xamppfiles/htdocs/PHP/adm/Axel.php:156)in 第243行/Applications/XAMPP/xamppfiles/htdocs/PHP/adm/Axel.php
<?php
$username = $_GET['username'];
if ($_POST) {
$con = mysql_connect("localhost", "inmoti6_myuser", "mypassword");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("inmoti6_mysite", $con);
$username = $_GET['username'];
$username = mysql_real_escape_string($username);
$users_comment = $_POST['comment'];
$users_comment = mysql_real_escape_string($users_comment);
$query = "INSERT INTO `inmoti6_mysite`.`comments` (`id`, `name`, `comment`,`timestamp`) VALUES (NULL, '$username', '$users_comment', CURRENT_TIMESTAMP);";
if ($users_comment == "") {
echo"Please write a comment.";
} else {
mysql_query($query);
echo "<h2>Thank you for your Comment!</h2>";
mysql_close($con);
}
}
?>
<h1>This is page1.php</h1>
<div style='margin:20px; width:100px; height:100px; background:blue;'></div>
<?php
$con = mysql_connect("localhost", "inmoti6_myuser", "mypassword");
$username = $_GET['username'];
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("inmoti6_mysite", $con);
$query = "SELECT * FROM `comments`";
$comments = mysql_query($query);
echo "<h1>User Comments</h1>";
while ($row = mysql_fetch_array($comments, MYSQL_ASSOC)) {
$username = $_GET['username'];
$name = $row['name'];
$comment = $row['comment'];
$timestamp = $row['timestamp'];
$name = htmlspecialchars($row['name'], ENT_QUOTES);
$comment = htmlspecialchars($row['comment'], ENT_QUOTES);
echo " <div style='margin:30px 0px;'>
Name: $name<br />
Comment: $comment<br />
Timestamp: $timestamp
</div>
";
}
mysql_close($con);
?>
<?php
$username = $_GET['username'];
echo "<form action='Axel.php?username=$username' method='post' submit=true>
Comment:<br />
<textarea name='comment' id='comment'></textarea><br />
<input type='submit' value='Submit' />
</form>";
?>