14c09-3.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 78 行

PHP
78
字号
<?php// This is the actual blog script itself.  Do some database prep:require_once '14c09-1.php';//require_once 'bloglib.php';$db = blog_connect();// Now first of all, see if we were posted to.if (count($_POST)) {    // Ok, handle doing the insert or update that was requested.    // Check the password!    if ($_POST['pass'] != 'letmein') {        die('ERROR: Unauthorized Access');    }        // Ok, we are here, so handle it.    if (trim($_POST['what'])) {        // Prep the date        date_default_timezone_set('America/New_York');        $ddate = date("M j, Y  h:i a");        // Prep the data, and insert it.        $wwhat = sqlite_escape_string(trim($_POST['what']));        blog_query($db, "            insert into blog (date, what)            values ('{$ddate}', '{$wwhat}')            ");    }}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Mini-Blog!</title><style>div.entry {    border: 1px solid red;    padding: 0px 5px;    margin: 0px 0px 30px 0px;}div.date {    float: right;    font-size: 80%;}</style></head><body><h1>The Blog!</h1><?php// We need to prepare to display the blog.  Read in the last 5 entries:$rs = blog_query($db, "    select date, what    from blog    order by id desc    limit 5");// Now loop through them all, printing them outwhile ($row = $rs->fetch()) {    echo "<div class=\"entry\">{$row['what']}<div class=\"date\">{$row['date']}</div></div>\n";}// Now quickly give them the ability to add a new entry:?><form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">New Entry:<input name="what" type="text" id="what" size="60" />&nbsp; Passcode:<input name="pass" type="password" id="pass" size="10" maxlength="10" />&nbsp;<input type="submit" name="Submit" value="Update" /></form></body></html><?php// Now close the connectionunset($db);?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?