栏目添加
// catadd.php
<meta charset="utf8">
<?php
if( empty($_POST) ) {
include('./view/admin/catadd.html');
} else {// 有数据提交,有点击提交按钮
// print_r($_POST);
$conn = mysql_connect('localhost', 'root', '');
mysql_query('use blog', $conn);
mysql_query('set names utf8');
// 检测栏目是否为空或空格
$cat['catname'] = trim( $_POST['catname'] );
if( empty($cat['catname']) ) {
echo "栏目不能为空";
exit();
}
// 检测栏目名是否已存在
$sql = "select count(*) from cat where catname='$cat[catname]'";// 查不到返回0
$rs = mysql_query($sql);// 执行返回资源
$catnum = mysql_fetch_row($rs);// 执行返回数组
if($catnum[0] != 0) {
echo "栏目已经存在";
exit();
}
// 插入cat表
$sql = "insert into cat (catname) values ('$cat[catname]')";
if( !mysql_query($sql) ) {// 插入返回的是boolean
// echo "栏目插入失败";
echo mysql_error();
}
else {
echo "栏目插入成功";
}
}
?>
网友评论