用PHP和MySQL構建一個資料庫驅動的網站(7)

來源:互聯網
上載者:User
現在我們已經有了允許使用者輸入一個笑話並將其加入到我們的資料庫中的程式碼。現在剩下的就是將其加入到我們已做好的笑話顯示頁面。因為絕大多數的使用者只會想要看看笑話,所以我們不想對我們的頁面做大的更改,除非使用者表示想要添加一個新的笑話。因為這個原因,我們的應用程式應該是一個多功能的頁面。下面是程式的代碼:
<HTML>
...
<BODY>
<?php
    // If the user wants to add a joke
    if (isset($addjoke)):
?>
<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
<P>Type your joke here:<BR>
<TEXTAREA NAME="joketext" ROWS=10 COLS=40 WRAP></TEXTAREA><BR>
<INPUT TYPE=SUBMIT NAME="submitjoke" VALUE="SUBMIT">
</FORM>
<?php
    else:
    // Connect to the database server
    $dbcnx = @mysql_connect("localhost",
        "root", "mypasswd");
    if (!$dbcnx) {
        echo( "<P>Unable to connect to the " .
       "database server at this time.</P>" );
        exit();
    }
    // Select the jokes database
    if (! @mysql_select_db("jokes") ) {
        echo( "<P>Unable to locate the joke " .
       "database at this time.</P>" );
        exit();
    }
    // If a joke has been submitted,
    // add it to the database.
    if ("SUBMIT" == $submitjoke) {

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.