課程內容
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
關於課程

favoriteinsert.php

<?php
session_start();
if (isset($_SESSION[‘customer’])) {
    $pdo=new PDO(‘mysql:host=localhost;dbname=shop;charset=utf8’,
        ‘root’, ‘12345678’);
    $sql=$pdo->prepare(‘insert into favorite values(?,?)’);
    $sql->execute([$_SESSION[‘customer’][‘id’], $_REQUEST[‘id’]]);
    echo ‘商品加入我的最愛成功。’;
    echo ‘<hr>’;
    require ‘favorite.php’;
} else {
    echo ‘請先登入,才能將商品加入我的最愛。’;
}
?>
 
favorite.php
 
<?php
if (isset($_SESSION[‘customer’])) {
    echo ‘<table>’;
    echo ‘<th>商品編號</th><th>商品名稱</th><th>價格</th>’;
    $pdo=new PDO(‘mysql:host=localhost;dbname=shop;charset=utf8’,
        ‘root’, ‘12345678’);
    $sql=$pdo->prepare(
        ‘select * from favorite, product ‘.
        ‘where customer_id=? and product_id=id’);
    $sql->execute([$_SESSION[‘customer’][‘id’]]);
    foreach ($sql->fetchAll() as $row) {
        $id=$row[‘id’];
        echo ‘<tr>’;
        echo ‘<td>’, $id, ‘</td>’;
        echo ‘<td><a href=”detail.php?id=’.$id.'”>’, $row[‘name’],
            ‘</a></td>’;
        echo ‘<td>’, $row[‘price’], ‘</td>’;
        echo ‘<td><a href=”favoritedelete.php?id=’, $id,
            ‘”>刪除</a></td>’;
        echo ‘</tr>’;
    }
    echo ‘</table>’;
} else {
    echo ‘請先登入,才能顯示我的最愛。’;
}
?>
 
favoritedelete.php
 
<?php
session_start();
if (isset($_SESSION[‘customer’])) {
    $pdo=new PDO(‘mysql:host=localhost;dbname=shop;charset=utf8’,
        ‘root’, ‘12345678’);
    $sql=$pdo->prepare(
        ‘delete from favorite where customer_id=? and product_id=?’);
    $sql->execute([$_SESSION[‘customer’][‘id’], $_REQUEST[‘id’]]);
    echo ‘所選商品已從我的最愛移除。’;
    echo ‘<hr>’;
} else {
    echo ‘請先登入,才能從我的最愛移除商品。’;
}
require ‘favorite.php’;
?>
favorite.show.php
 
<?php
session_start();
require ‘favorite.php’;
?>