Head First PHP&MySQl第二章代碼

PHP:php

<html>

<head>
    <title>外星人綁架了我--報道一塊兒綁架</title>
</head>

<body>
    <h2>外星人綁架了我--報道一塊兒綁架</h2>

    <?php
    $name = $_POST['name'];
    $when_it_happened = $_POST['whenithappened'];
    $how_long = $_POST['howlong'];
    $how_many = $_POST['howmany'];
    $alien_description = $_POST['aliendescription'];
    $what_they_did = $_POST['whattheydid'];
    $fang_spotted = $_POST['fangspotted'];
    $email = $_POST['email'];
    $other = $_POST['other'];

    //DatabaseAddress:數據庫地址;username:用戶名;command:口令;DatabaseName:數據庫名字;
    $dbc = mysqli_connect('DatabaseAddress','username','command','DatabaseName')
        or die('鏈接MySQL錯誤.');

    //參數與數據庫的表單的列有關
    $query = "TNSERT INTO TableName (name, when_it_happened, how_long, ".
        "how_many, alien_description, what_they_did, fang_spotted, other, email)".
        "VALUES (' $name, $when_it_happened, $how_long, $how_many, ".
        "$alien_description, $what_they_did, $fang_spotted, $other, $email)";
    $result = mysqli_query($dbc, $query)
        or die('查詢數據庫錯誤。');
    mysqli_close($dbc);

    echo '很是感謝你提交的表單 ' . '<br/>';
    echo  '你在何時被綁架的?' . $when_it_happened . '<br/>';
    echo '你被帶走了多長時間? ' . $how_long . '<br/>';
    echo '外星人的數量是多少? ' . $how_many . ' <br/>';
    echo  ' 外星人的外貌是什麼樣? ' . $alien_description . '<br/>';
    echo '外星人作了什麼? ' . $what_they_did . '<br/>';
    echo 'Fang在不在那裏? ' . $fang_spotted . ' < br/>';
    echo '其它內容: ' . $other . '<br/>';
    echo '你的郵箱地址是: ' . $email . '<br/>';
    ?>
</body>

</html>
相關文章
相關標籤/搜索