/var/www/hkosl.com/dirsignage/html/webadmin/company_delete.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
    
include 'config.php';

    
// Check if the user is logged in

    
if ((!isSet($_SESSION['loginname'])) || ($loggin <> '1')) {
        
header("Location: login.php");
        exit;
    }

    
$id = (int)$_GET["id"];

    
//update sort for others
    /*$sql = "select * from company where id = ? ";
    $parameters = array($id);
    if (!($sth = $dbh->prepare($sql))) {
        throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
        exit;
    }

    if (!$sth->execute($parameters)) {
        throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
        exit;
    }
    $category_info = $sth->fetch(PDO::FETCH_ASSOC);
    $sort = $category_info{"sort"};


    $sql = "update company set sort = sort - 1 where sort > ?";
    $parameters = array($sort);
    if (!($sth = $dbh->prepare($sql))) {
        throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
    }

    if (!$sth->execute($parameters)) {
        throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
    }*/

    // Delete db
    
$sql2 "update company set deleted = ? WHERE id=?";

    if (!(
$sth2 $dbh->prepare($sql2))) {
        throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth2->errorInfo()));
    }

    if (!
$sth2->execute(array("1"$id))) {
        throw new 
Exception('[' $sth2->errorCode() . ']: ' print_r($sth2->errorInfo()));
    }

    
$dbh null;

    
header("Location: company_index.php?msg=刪除成功");

?>