您的位置:首页 > 其它

2011-10-13 新闻发布系统制作3

2011-10-13 15:28 239 查看
新闻发布系统首页—— index.php

<?php

include("header.php");

include("dbconnect.php");

//检索数据库的分类表tbl_category,

$sql="select * from tbl_category order by id desc";

$res=mysql_query($sql);

//循环方式显示新闻栏目

while($row=mysql_fetch_array($res)){

$categorys[$row["id"]]=$row["category_name"];

?>

<a href="list.php?category=<?php echo $row["id"];?>"><?php echo $row["category_name"];?></a>

<!--假如当前为管理员,每个栏目可以进行编辑-->

<?php

if($_SESSION["level"]==1){

?>

<a href="admin_editnews.php?id=<?php echo $row["id"];?>"><font color="red">编辑</font></a>

<?php

}

?>

<?php

}

include("footer.php");

?>

登陆界面——login.php

<?php

//验证用户的登录

include("dbconnect.php");

//如果点击“退出”

if(@$_GET['do']=="logout"){

}

//判断登录情况

if(@$_GET['do']==1){

//防止SQL注入(攻击)

//mysql_real_escape_string();

//功能:转换字符串中特殊字符

$username=mysql_real_escape_string($_POST["username"]);

$password=mysql_real_escape_string($_POST["password"]);

$message="";

//如果用户名没填,提醒

if($username==""){

$message.="username is not null!";

}

//如果口令没填,提醒

if($password==""){

$message.="password is not null!";

}

//如果用户信息完整,验证与数据库中记录的一//致性;

if($message==""){

//先查找与输入的用户匹配的记录

$sql="select * from tbl_user

where username='{$username}' and level='admin' limit 1 ";

//把用户传入的口令加密后与记录进行匹配

if($res=mysql_query($sql)){

$row=mysql_fetch_array($res);

//当表格里的password字段有长度限制时??

//password varchar(20)

//使用截取字符串函数

if(md5($password)==$row['password']){

$_SESSION['level']=1;

$_SESSION['username']=$username;

header("location:index.php");

exit;

}else{

$_SESSION['level']=0;

$_SESSION['username']=$username;

header("location:index.php");

exit;

}

}

}

echo $message;

}

//实现登录界面

?>

<form action="login.php?do=1" method="post" name="myform">

用户名:<input type="text" name="username" />

口令:<input type="password" name="password" />

<input type="submit" name="submit" value="登录">

</form>

添加栏目文件——admin_category.php

<?php

include("config.php");

include("dbconnect.php");

?>

<!--添加栏目-->

<form name="myform" method="post" action="add_category.php">

<select name="myselect">

<option value="0">-请选择所属栏目-</option>

<?php

$sql="select * from tbl_category ";

$res=mysql_query($sql);

//mysql_fetch_array $row['id'] $row[0]

//mysql_fetch_assoc $row['id']

//mysql_fetch_row $row[0]

while($row=mysql_fetch_array($res)){

//统计要增加的缩进符号的数量$num

//explode:拆分字符串,返回数组

//数组名称表示长度

//count()函数统计元素的个数

//分隔符的数量=长度-1

$num = count(explode("-",$row['path']))-1;

//每循环一次之后缩进符号内容清零

$string="";

for($i=0;$i<$num;$i++){

//定义缩进符号:空格、-、#等

$string.="--";

}

//将缩进符与栏目名称结合

?>

<option value="<?php

//1、使用不同的分隔符,0-1#3

//2、选择分割后的数组中最后一个元素,0-1-3

echo $row['path']."#".$row['id'];

?>"><?php echo $string.$row['category_name'];?></option>

<?php

}

?>

</select>

新栏目名称:<input type="text" name="name">

<input type="submit" value="添加">

</from>

添加栏目文件执行文件——add_category.php

<?php

include("config.php");

include("dbconnect.php");

//用户点击“添加”按钮后将新栏目写入到tbl_category

//path=父栏目的path与子栏目的pid结合

//pid=1、父栏目的id;2、path字段拆分后的最后一个字符串

//从“添加栏目”页面获取path字段值

//结合后insert into

//1、接收新栏目的信息

//id:atuo_increment,null

//category_name

$name = $_POST['name'];

//pid paht

$type = $_POST['myselect'];

//0-1#7 $arr = explode("#","0-1#7"); $arr[0]=0-1 $arr[1]=7

$arr = explode("#",$type);

echo $arr[0];

echo "<br>";

echo $arr[1];

echo "<br>";

echo $type;

echo "<br>";

$sql = "insert into tbl_category values(null,'".$name."',".$arr[1].",'".$arr[0]."-".$arr[1]."')";

echo $sql;

mysql_query($sql);

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: