[英]I need help finding what is wrong with my code. This is from Larry Ullman's Book PHP for the Web
I am studying this book from Larry Ullman, PHP for The Web, and I am stuck on Chapter 12 script 5. The first scripts worked just fine. 我正在从Web上的PHP的Larry Ullman学习这本书,而我只停留在第12章脚本5上。第一个脚本工作得很好。 Can anyone spot my error?
谁能发现我的错误? My operating system is ubuntu 14.04 and I am using LAMP with PHP 5.5.9.
我的操作系统是ubuntu 14.04,并且我将LAMP与PHP 5.5.9一起使用。
<?php // Script 12.5 - add_entry.php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Connect and select:
$dbc = mysql_connect('localhost', 'root', '*******');
mysql_select_db('myblog', $dbc);
// Validate the form data
$problem = FALSE;
if (!empty($_POST['title']) && !empty($_POST['entry'])) {
$title = trim(strip_tags(S_POST['title']));
$entry = trim(strip_tags($_POST['entry']));
} else {
print '<p style="color: red;">Please submit both a title and an entry.</p>';
$problem = TRUE;
}
if (!$problem) {
// Define the query:
$query = "INSERT INTO entries (entry_id, title, entry, date_entered) VALUES (0, '$title', '$entry', NOW())";
if (@mysql_query($query, $dbc)) {
print '<p>The blog entry has been added!<p>';
} else {
print '<p style="color: red;">Could not add the entry because:<br />' . mysql_error($dbc) . '.</p><p>The query being run was:' . $query . '</p>';
}
} // No Problem!
mysql_close($dbc); // Close the connection
} // End of form submission IF
?>`
You have: 你有:
$title = trim(strip_tags(S_POST['title'])); // note S instead of $
Change that to: 更改为:
$title = trim(strip_tags($_POST['title']));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.