php练手代码之微型论坛设计(2)

来源:互联网 发布:mysql数据库迁移方案 编辑:程序博客网 时间:2024/05/16 10:25

接着上一篇的

 

将微型论坛大致功能写出来之后,刚在中秋节之前,终于是收到了一份offer,否则都没脸回家过节了,不管怎样,学php之后,终于是找到了一份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" lang = "zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form name = "login" action = "loginProcess.php" method = "post">
<table width = "400" border = "1" align = "center" cellpadding = "5" cellspacing = "1"
>
<tr id = "title">
<td colspan = "2">用户登录</td>
</tr>

<tr>
<td width = "23%" >用户名</td>
<td width = "77%"><input name = "username" type = "text" class = "input"
id = "username" /></td>
</tr>

<tr>
<td width = "23%" >密&nbsp;码</td>
<td width = "77%"><input name = "password" type = "password" class = "input"
id = "password" /></td>
</tr>

<tr>
<td></td>
<td>
<input name = "Submit" type = "submit" class = "btn" value = "登录"/>
<input name = "Submit" type = "reset" class = "btn" value = "重填"/>
</td>
</tr>

</table>
</form>
<?php
 //接收errno
 if (!empty($_GET['errno'])){
  
  //接收错误编号
  $errno=$_GET['errno'];
  if ($errno==1) {
   echo "<br/><p align = 'center'><font color='red' size='3'>你的用户名或密码错误</font></p>";
  }
 }
 
?>
</body>
</html>

 

接着就是首页面了

<?php session_start(); ?>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
</head>
<?php
 require_once 'conn.php';
 require_once 'global.php';
 echo '<h1 align = "center">'.$gb_name.'</h1>';
 if (!isset($_SESSION['username'])) {
  echo '<p><a href = "login.php">登录&nbsp;</a><a href = "register.php">注册</a></p>';
 }else{
  echo $_SESSION["username"].'<p><a href = "control.php">我的资料</a>
  <a href = "manageForums.php">论坛管理</a>
  <a href = "loginout.php">退出</a></p>';
 }
 
?>
<form>
<table width = "90%" border = "1" align = "center" cellpadding = "5" cellspacing = "1"
>
<tr>
<td colspan = "3">论坛列表</td>
</tr>
<tr>
<td width = "6%"><strong>状态</strong></td>
<td width = "70%"><strong>论坛</strong></td>
<td width = "24%"><strong>最后更新</strong></td>
</tr>
<?php

 $sql = 'select * from forums';
 
 $result = mysql_query($sql,$conn);
 
 $num = mysql_num_rows($result);
 if($num > 0){
  while($row = mysql_fetch_array($result)){
  //var_dump($row);
  ?>
   <tr>
   <td></td>
   <td>
   <?php echo "
   <div class = \"bold\">
   <a clss = \"forum\" href = \"topicList.php?id=".$row["id"]."\">
   ".$row["forum_name"]."
   </a>
   </div>"
   .$row["forum_description"];
   ?>
   </td>
   <td>
   <div>
   <?php
    echo $row['last_post_time'].'By'
    .$row['last_post_author'];
   ?>
   </div>
   </td>
   </tr>
   <?php
  }
 }else{
  echo '<tr><td colspan = "3">对不起,论坛尚在建设中······</td></tr>';
 }
 close_db();

?>
</table>
</form>
</html>

 

今天暂时到这吧,这里说一下的是,因为没有放数据库表的设计文件,所以有些地方看起来是比较迷惑的,不过如果对照着前一篇的设计框架图来看的话,应该是比较容易的

 

 

 

0 0