— <br />
— 表的结构 book
<br />
— <br />
<br />
<br />
Create TABLE book
(<br />
id
int(8) NOT NULL auto_increment,<br />
username
varchar(50) default NULL,<br />
qq
varchar(50) default NULL, <br />
email
varchar(50) default NULL,<br />
title
varchar(50) default NULL,<br />
content
text,<br />
time
varchar(50) default NULL,<br />
retime
varchar(50) default NULL,<br />
recon
text,<br />
PRIMARY KEY (id
)<br />
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;<br />
<br />
<br />
<br />
— <br />
— 导出表中的数据 book
<br />
— <br />
<br />
<br />
— ——————————————————–<br />
<br />
— <br />
— 表的结构 users
<br />
— <br />
<br />
<br />
<br />
Create TABLE users
(<br />
id
int(8) NOT NULL auto_increment,<br />
username
varchar(50) default NULL,<br />
userid
varchar(50) default NULL,<br />
password
varchar(50) default NULL,<br />
email
varchar(50) default NULL,<br />
PRIMARY KEY (id
)<br />
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;<br />
<br />
<br />
— <br />
— 导出表中的数据 users
<br />
— <br />
<br />
<br />
上面的是sql<br />
<br />
添加记录add.php<br />
<br />
<br />
<br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head><br />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><br />
<title>添加留言</title><br />
<style type="text/css"><br />
<!–<br />
body,td,th {<br />
font-size: 12px;<br />
color: #333333;<br />
font-family: 宋体;<br />
}<br />
a {<br />
font-size: 12px;<br />
color: #333333;<br />
font-family: 宋体;<br />
}<br />
a:link {<br />
text-decoration: none;<br />
}<br />
a:visited {<br />
text-decoration: none;<br />
color: #333333;<br />
}<br />
a:hover {<br />
text-decoration: none;<br />
color: #FF0000;<br />
}<br />
a:active {<br />
text-decoration: none;<br />
color: #0000FF;<br />
}<br />
body {<br />
margin-left: 0px;<br />
margin-top: 20px;<br />
margin-right: 0px;<br />
margin-bottom: 0px;<br />
}<br />
.input1 {<br />
height: 20px;<br />
width: auto;<br />
border-top-width: 1px;<br />
border-right-width: 1px;<br />
border-bottom-width: 1px;<br />
border-left-width: 1px;<br />
border-top-style: solid;<br />
border-right-style: solid;<br />
border-bottom-style: solid;<br />
border-left-style: solid;<br />
border-top-color: #666666;<br />
border-right-color: #CECFCE;<br />
border-bottom-color: #CECFCE;<br />
border-left-color: #636563;<br />
}<br />
.con {<br />
height: auto;<br />
width: auto;<br />
border-top-width: 1px;<br />
border-right-width: 1px;<br />
border-bottom-width: 1px;<br />
border-left-width: 1px;<br />
border-top-style: solid;<br />
border-right-style: solid;<br />
border-bottom-style: solid;<br />
border-left-style: solid;<br />
border-top-color: #666666;<br />
border-right-color: #CECFCE;<br />
border-bottom-color: #CECFCE;<br />
border-left-color: #636563;<br />
overflow: auto;<br />
}<br />
.red {<br />
color: #FF0000;<br />
}<br />
–><br />
</style><br />
</head><br />
<br />
<body><br />
<?<br />
if($username!="")<br />
{<br />
$ID = uniqid("bookID");<br />
$db = mysql_connect("localhost","root","");<br />
mysql_select_db ("wpsni");<br />
$add_time=date("Y")."-".date("m")."-".date("d")." ".date("H").":".date("i").":".date("s"); <br />
$result = mysql_query ("insert into book (id, username,email , qq, title,content,time)<br />
VALUES ('$ID', '$username', '$email', '$qq','$title','$content','$add_time')");<br />
if(!$result)<br />
{<br />
echo "<center>出现错误:</center>", mysql_error();<br />
exit;<br />
}<br />
if($result)<br />
{<br />
mysql_close($db);<br />
echo "<center>用户 <b>$username</b> 留言成功!</center>";<br />
}<br />
}<br />
else<br />
{<br />
echo "<center>资料填写不完整,请仔细填写!</center>";<br />
?><br />
<table width="415" height="297" border="0" align="center" cellpadding="0" cellspacing="0" background="images/add_bg.gif"><br />
<tr><br />
<td height="35" colspan="2" align="center" valign="top"><img src="images/add_top.gif" width="489" height="35" /></td><br />
</tr><br />
<tr><br />
<td height="232" colspan="2"><form id="form1" name="form1" method="post" action="add.php"><br />
<table width="424" height="142" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#EBEBEB"><br />
<tr><br />
<td width="42" bgcolor="#FFFFFF">名 字</td><br />
<td width="359" height="25" bgcolor="#FFFFFF"><label><br />
<input name="username" type="text" class="input1" id="username" size="20" /><br />
<span class="red"> * </span></label></td><br />
</tr><br />
<tr><br />
<td height="26" bgcolor="#FFFFFF">Q Q</td><br />
<td height="25" bgcolor="#FFFFFF"><label><br />
<input name="qq" type="text" class="input1" id="qq" size="10" /><br />
</label></td><br />
</tr><br />
<tr><br />
<td bgcolor="#FFFFFF">Email</td><br />
<td height="25" bgcolor="#FFFFFF"><label><br />
<input name="email" type="text" class="input1" id="email" size="20" /><br />
</label></td><br />
</tr><br />
<tr><br />
<td bgcolor="#FFFFFF">标 题</td><br />
<td height="25" bgcolor="#FFFFFF"><label><br />
<input name="title" type="text" class="input1" id="title" size="30" /><br />
<span class="red">* </span></label></td><br />
</tr><br />
<tr><br />
<td bgcolor="#FFFFFF">内 容</td><br />
<td bgcolor="#FFFFFF"><label><br />
<textarea name="content" cols="45" rows="8" class="con" id="content"></textarea><br />
<span class="red">* </span></label></td><br />
</tr><br />
<tr><br />
<td colspan="2" bgcolor="#FFFFFF"><div align="center"><br />
<label><br />
<input type="submit" name="Submit" value="提交" /><br />
</label><br />
<label><br />
<input type="reset" name="Submit2" value="重置" /><br />
</label><br />
</div></td><br />
</tr><br />
</table><br />
</form><br />
</td><br />
</tr><br />
<tr><br />
<td height="30" colspan="2" align="center" valign="bottom"><img src="images/add_end.gif" width="489" height="30" /></td><br />
</tr><br />
</table><br />
<?<br />
}<br />
?><br />
</body><br />
</html><br />
<br />
<br />
<br />
<br />
显示index.php<br />
<br />
<HTML><br />
<HEAD><br />
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"><br />
<style type="text/css"><br />
<!–<br />
input { font-size:9pt;}<br />
A:link {text-decoration: underline; font-size:9pt;color:000059}<br />
A:visited {text-decoration: underline; font-size:9pt;color:000059}<br />
A:active {text-decoration: none; font-size:9pt}<br />
A:hover {text-decoration:underline;color:red}<br />
body,table {font-size: 9pt}<br />
tr,td{font-size:9pt}<br />
–><br />
</style><br />
<title>注册会员列表 – 读取mysql的测试</title><br />
</HEAD><br />
<?<br />
//连接到本地mysql数据库<br />
$myconn=mysql_connect("localhost","root","");<br />
//选择test为操作库<br />
mysql_select_db("wpsni",$myconn);<br />
$strSql="select * from book";<br />
//用mysql_query函数从book表里读取数据<br />
$result=mysql_query($strSql,$myconn);<br />
while($row=mysql_fetch_array($result))//通过循环读取数据内容<br />
{<br />
?><br />
<br />
<table width="356" height="166" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF"><br />
<tr><br />
<td width="42" bgcolor="#CACACA"><samp>姓名</samp></td><br />
<td width="300" bgcolor="#E4E4E4"><?echo $row["username"]?></td><br />
</tr><br />
<tr><br />
<td bgcolor="#CACACA">QQ</td><br />
<td bgcolor="#E4E4E4"><?echo $row["qq"]?></td><br />
</tr><br />
<tr><br />
<td bgcolor="#CACACA">email</td><br />
<td bgcolor="#E4E4E4"><?echo $row["email"]?></td><br />
</tr><br />
<tr><br />
<td bgcolor="#CACACA">标题</td><br />
<td bgcolor="#E4E4E4"><?echo $row["title"]?></td><br />
</tr><br />
<tr><br />
<td bgcolor="#CACACA">内容</td><br />
<td bgcolor="#E4E4E4"><?echo $row["content"]?></td><br />
</tr><br />
<tr><br />
<td bgcolor="#CACACA">时间</td><br />
<td bgcolor="#E4E4E4"><?echo $row["time"]?></td><br />
</tr><br />
</table><br />
<br><br />
<?<br />
}<br />
//关闭对数据库的连接<br />
mysql_close($myconn);<br />
?><br />
</BODY><br />
</HTML>