forked from niannianli/Shopping-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.inc.php
116 lines (97 loc) · 2.38 KB
/
config.inc.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**********************/
/* system parameter setting */
/**********************/
//database
define('DB_USER', "root"); //user name
define('DB_PASSWORD', "lilian"); //password
define('DB_HOST', "localhost"); //localhost
define('DB_NAME', "php_shop"); //database name
//administration
define('ADMIN_USER', "admin");
define('ADMIN_PW', "admin");
//records in every page
define('EACH_PAGE', 5);
//file upload path
define('UPLOAD_PATH',dirname(__FILE__)."/uploads/");
/**********************/
/* public function setting */
/**********************/
//function: show error infor, back page, end programm
//input: error infor, link
//output: error info
function ExitMessage($message, $url='')
{
echo '<p class="message">'. $message. '<br>';
if($url){
echo '<a href="'.$url.'">back</a>';
}else{
echo '<a href="#" onClick="window.history.go(-1);">back</a>';
}
echo '</p>';
exit;
}
//function: admin, show error
//input: error info array
//output: error info
function ShowErrorBox($error)
{
if(!is_array($error)){
$error = array($error);
}
$error_msg = '<ul>';
foreach($error as $err){
$error_msg .= "<li>$err</li>";
}
$error_msg .= '</ul>';
echo '<div class="error">' .$error_msg. '</div>';
}
//function: show category list
//input: error info, link
//output:char, string
function OptionCategories($selected_id=0)
{
global $db;
$sql = "SELECT * FROM categories ORDER BY category_name";
$result=mysql_query($sql);
while ($row=mysql_fetch_array($result))
{
$category_id=$row["category_id"];
$category_name=htmlspecialchars($row["category_name"]);
if($selected_id == $category_id)
{
echo '<option value="'.$category_id.'" selected>'.$category_name.'</option>';
}else{
echo '<option value="'.$category_id.'">'.$category_name.'</option>';
}
}
}
//html
//input: html
//output: string
function Html2Text($html)
{
return htmlspecialchars(stripslashes($html));
}
//char
//price
//, string
function MoneyFormat($price)
{
return number_format($price, 2, '.', ',');
}
/********************/
/* initial program */
/********************/
//start SESSION
@session_start();
//connect database
$db = mysql_pconnect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$db)
{
die('<b>fail to connect database.</b>');
exit;
}
//select database
mysql_select_db (DB_NAME);
?>