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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
<?php include 'config.php';
// Check if the user is logged in
if ((!isSet($_SESSION['loginname'])) || ($loggin <> '1')) { header("Location: login.php"); exit; }
$nowdate = date("Y-m-d H:i:s"); $model_code = $_POST["model_code"]; $series_id = $_POST["series_id"]; $serial_number = $_POST["serial_number"];
$sql = "select * from series where series_id=?"; if (!($sth = $dbh->prepare($sql))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); }
if (!$sth->execute(array($series_id))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); }
$row = $sth->fetch(PDO::FETCH_ASSOC); $region = $row{"region"}; $series_code= $row{"series_code"};
$sql = "select * from serial_number sn, model model, series series where sn.series_code = series.series_code and sn.model_code = model.model_code and sn.series_code = ? and sn.model_code = ? and sn.serial_number = ? and sn.deleted = ? and sn.region = ? and model.region = ? and series.region = ? group by sn.serial_number_id ";
if (!($sth = $dbh->prepare($sql))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); }
if (!$sth->execute(array($series_code, $model_code, $serial_number, "0", $region, $region, $region))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); }
if($sth->rowCount() > 0){ echo "<script type='text/javascript'> alert('此產品序號已存在!'); history.back(); </script>"; exit; }
$sql = "insert into serial_number (region, series_code, model_code,serial_number, createdate, createby, lastupdate, lastupby) values (?, ?, ?, ?, ?, ?, ?, ?)";
if (!($sth = $dbh->prepare($sql))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); }
$parameter = array($region, $series_code, $model_code, $serial_number, $nowdate, $_SESSION['cmsloginid'], $nowdate, $_SESSION['cmsloginid']);
if (!$sth->execute($parameter)) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); }
$dbh = null;
header("Location: serial_number_index.php?msg=Add Successful");
?>
|