-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertCategory.php
More file actions
60 lines (40 loc) · 1.3 KB
/
insertCategory.php
File metadata and controls
60 lines (40 loc) · 1.3 KB
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>
<?php
include 'database_connect.php';
if (!empty($_POST)) {
$sql = "INSERT INTO category (`parent_id`, `name`) VALUES ('{$_POST['parent_id']}', '{$_POST['name']}');";
if(mysql_query($sql, $dbconnect)) {
echo "插入成功!";
} else {
die("error: ".mysql_error());
};
}
$sql = "SELECT `cate_id`, `parent_id`, `name` FROM category";
$result = mysql_query($sql, $dbconnect);
while($row = mysql_fetch_array($result))
{
$categories[] = $row;
}
?>
<form action='insertCategory.php' method="post">
<select name="parent_id">
<option value="0">作为父类</option>
<?php foreach ($categories as $cate): ?>
<?php if($cate['parent_id'] == 0):?>
<option value="<?php echo $cate['cate_id']?>"><?php echo $cate['name'] ?></option>
<?php else:?>
<option value="<?php echo $cate['cate_id']?>"> -- <?php echo $cate['name'] ?></option>
<?php endif;?>
<?php endforeach; ?>
</select>
<input type="text" name="name" />
<input type="submit" value="插入" />
</form>
</body>
</html>