我需要帮助找到我的代码有什么问题。这是拉里·厄尔曼';s Book PHP for the Web
我正在学习拉里·厄尔曼(Larry Ullman)的这本书,PHP for The Web,我被困在第12章脚本5中。最初的脚本工作得很好。有人能发现我的错误吗?我的操作系统是Ubuntu14.04,我在PHP5.5.9中使用LAMP我需要帮助找到我的代码有什么问题。这是拉里·厄尔曼';s Book PHP for the Web,php,Php,我正在学习拉里·厄尔曼(Larry Ullman)的这本书,PHP for The Web,我被困在第12章脚本5中。最初的脚本工作得很好。有人能发现我的错误吗?我的操作系统是Ubuntu14.04,我在PHP5.5.9中使用LAMP <?php // Script 12.5 - add_entry.php if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Connect and select: $dbc = mysql_co
<?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
?>`
您有:
$title = trim(strip_tags(S_POST['title'])); // note S instead of $
改为:
$title = trim(strip_tags($_POST['title']));
当您尝试使用脚本时,收到的错误消息是什么?请确保在调试代码时启用。