課程內容
LAMP Stack —- 基礎篇
LAMP Stack 是最傳統建置網站的堆疊方法,亦是初學編程者的起步,雖然網站的建置方法發展到今天已極多元化,但HTML、 CSS 和JavaScript ,還是學習編程不可跳過的部份。 本章會集中建構一個完整的學習框架,讓我們可依此進一步探討。
0/84
LAMP Stack —- Libraries 與 Frameworks
0/64
LAMP Stack —- Embedded with NUXT2
0/115
財DEE的趣味編程 —- LAMP Stack
關於課程
<?php
session_start();
$name=$address=$login=$password=”;
if (isset($_SESSION[‘customer’])) {
    $name=$_SESSION[‘customer’][‘name’];
    $address=$_SESSION[‘customer’][‘address’];
    $login=$_SESSION[‘customer’][‘login’];
    $password=$_SESSION[‘customer’][‘password’];
}
echo ‘<form action=”customeroutput.php” method=”post”>’;
echo ‘<table>’;
echo ‘<tr><td>姓名</td><td>’;
echo ‘<input type=”text” name=”name” value=”‘, $name, ‘”>’;
echo ‘</td></tr>’;
echo ‘<tr><td>地址
</td><td>’;
echo ‘<input type=”test” name=”address” value=”‘, $address, ‘”>’;
echo ‘</td></tr>’;
echo ‘<tr><td>登入ID</td><td>’;
echo ‘<input type=”text” name=”login” value=”‘, $login, ‘”>’;
echo ‘</td></tr>’;
echo ‘<tr><td>密碼</td><td>’;
echo ‘<input type=”password” name=”password” value=”‘, $password, ‘”>’;
echo ‘</td></tr>’;
echo ‘</table>’;
echo ‘<input type=”submit” value=”確定”>’;
echo ‘</form>’;
?>

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

<?php

session_start();
$pdo=new PDO(‘mysql:host=localhost;dbname=shop;charset=utf8’,
    ‘root’, ‘12345678’);
if (isset($_SESSION[‘customer’])) {
    $id=$_SESSION[‘customer’][‘id’];
    $sql=$pdo->prepare(‘select * from customer where id!=? and login=?’);
    $sql->execute([$id, $_REQUEST[‘login’]]);
} else {
    $sql=$pdo->prepare(‘select * from customer where login=?’);
    $sql->execute([$_REQUEST[‘login’]]);
}
if (empty($sql->fetchAll())) {
    if (isset($_SESSION[‘customer’])) {
        $sql=$pdo->prepare(‘update customer set name=?, address=?, ‘.
            ‘login=?, password=? where id=?’);
        $sql->execute([
            $_REQUEST[‘name’], $_REQUEST[‘address’],
            $_REQUEST[‘login’], $_REQUEST[‘password’], $id]);
        $_SESSION[‘customer’]=[
            ‘id’=>$id, ‘name’=>$_REQUEST[‘name’],
            ‘address’=>$_REQUEST[‘address’], ‘login’=>$_REQUEST[‘login’],
            ‘password’=>$_REQUEST[‘password’]];
        echo ‘客戶資料修改完成。’;
    } else {
        $sql=$pdo->prepare(‘insert into customer values(null,?,?,?,?)’);
        $sql->execute([
            $_REQUEST[‘name’], $_REQUEST[‘address’],
            $_REQUEST[‘login’], $_REQUEST[‘password’]]);
        echo ‘客戶資料新增完成。’;
    }
} else {
    echo ‘登入ID已被使用,請重新設定。’;
}
?>