数据库连接
来源:互联网 发布:网络砍价师 编辑:程序博客网 时间:2024/04/28 01:48
config.php页面
<?php
//防止产生乱码
header("Content-type:text/html;charset=utf-8");
//定义常量
define('HOST','localhost');
define('USERNAME','root');
define('PASSWORD','');
?>
connect.php页面
<?php
//导入config.php
require_once('config.php');
//连库,如果连接失败打印错误信息
if(!( $con=mysql_connect(HOST,USERNAME,PASSWORD))){
echo mysql_error();
}
//选库
if(!(mysql_select_db('info'))){
echo mysql_error();
}
//字符集
if(!(mysql_query('set names utf8'))){
echo mysql_error();
}
?>
article.php页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
</style>
</head>
<body>
<table width="100%" height="520" border="0" cellpadding="8" cellspacing="1" bgcolor="#000000">
<tr>
<td height="89" colspan="2" bgcolor="#FFFF99"><strong>后台管理系统</strong></td>
</tr>
<tr>
<td width="156" height="287" align="left" valign="top" bgcolor="#FFFF99"><p><a href="article.add.php">发布文章</a></p>
<p><a href="article.manage.php">管理文章</a></p> <a href="article.add.php"></a></td>
<td width="837" valign="top" bgcolor="#FFFFFF">
<form id="form1" name="form1" method="post" action="article.add.handle.php">
<table width="779" border="0" cellpadding="8" cellspacing="1">
<tr>
<td colspan="2" align="center">发布文章</td>
</tr>
<tr>
<td width="119">标题</td>
<td width="625"><label for="title"></label>
<input type="text" name="title" id="title" /></td>
</tr>
<tr>
<td>作者</td>
<td><input type="text" name="author" id="author" /></td>
</tr>
<tr>
<td>简介</td>
<td><label for="description"></label>
<textarea name="description" id="description" cols="60" rows="5"></textarea></td>
</tr>
<tr>
<td>内容</td>
<td><textarea name="content" cols="60" rows="15" id="content"></textarea></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="button" id="button" value="提交" /></td>
</tr>
</table>
</form></td>
</tr>
<tr>
<td colspan="2" bgcolor="#FFFF99"><strong>版权所有</strong></td>
</tr>
</table>
</body>
</html>
article.add.handle.php
<?php
require_once('connect.php');
//把传递过来的信息入库,在入库前对信息进行校验
// print_r($_POST);
//isset判断变量是否存在
if(isset($_POST['title'])&&(!empty($_POST['title']))){
echo "<script>alert('标题不能为空');
window.location.href='article.add.php'</script>";
}
$title=$_POST['title'];
$author=$_POST['author'];
$description=$_POST['description'];
$content=$_POST['content'];
$dateline=time();
$insertsql="insert into article(title,author,description,content,dateline)
values('$title','$author','$description','$content','$dateline')";
//echo $insertsql;
// echo "标题不能为空";
if(mysql_query($insertsql)){
echo "<script>alert('文章发表成功');
window.location.href='article.add.php'</script>";
}else{
echo "<script>alert('文章发表失败');
window.location.href='article.add.php'</script>";
}
?>
- 数据库连接
- 数据库连接
- 数据库连接
- 数据库连接
- 数据库连接
- 数据库连接
- 数据库连接
- 数据库连接
- 数据库连接
- 数据库连接
- 数据库连接
- 数据库连接
- 数据库连接
- 数据库连接
- 数据库连接
- 数据库连接
- 数据库连接
- 数据库连接
- 数据结构实践项目之校园导航系统
- nexus中自定义仓库
- C++数组
- SqlServer与Oracle语法差异
- 基于顺序表的两个非递减有序表的合并
- 数据库连接
- DHT 爬虫的学习记录
- 笔记
- 发布几个PDF小工具
- 条件编译符号与发布
- 【Docker技术入门与实战】存出和载入镜像
- Cacti 访问 URL的变更
- window向linux传文件
- 《Word排版艺术》读后感——兼谈与LaTeX的比较