+ -
当前位置:首页 → 问答吧 → 分享一下我第一个PHP的作品

分享一下我第一个PHP的作品

时间:2008-11-10

来源:互联网

这是个用PHP写的留言板,当中加入了分页功能,发图功能正在想办法改进中!!

[php]
$conn=@ mysql_connect("localhost","root","") or die ("连接失败");
mysql_select_db("newdb",$conn);
mysql_query("set names 'GBK'");

function htmltocode($a)
{
    $a=str_replace("img src","img src",str_replace(" "," ",str_replace("\n","<br>",$a)));
    return $a;
}
if($_POST['Submit'])
{
    $sql="insert into newsay (id,name,sex,time,content) values ('','$_POST[user]','$_POST[sex]',now(),'$_POST[content]')";
    mysql_query($sql,$conn);
    $result =mysql_error();
    echo $result;
    setcookie("newsayname","$_POST[user]");
}
?><head>
<style type="text/css">
<!--
.STYLE1 {color: #FF0000}
-->
</style>
<script language="JavaScript">
function CheckPost()
{
    if(form1.content.value=="")
    {
        alert("请填写内容");
        form1.content.focus();
        return false;
    }
}
</script>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>雄留言板</title>
<style type="text/css">body {
    background-image: url(image/wallpage54.jpg);
}
body,td,th {
    font-family: 宋体;
    color: #000000;
}
</style></head>



<body tracingsrc="image/wallpage54.jpg" tracingopacity="50"><form id="form1" name="form1" method="post" action="add.php" onSubmit="return CheckPost();">
  <label>
  <div align="center">姓名
    <input name="user" type="text" id="user" value="<?php echo $_COOKIE['newsayname']?>"/>
        性别
<input type="radio" name="sex" value="男" />

  <input type="radio" name="sex" value="女" />
  女
  </div>
  <p align="center">内容
    <label>
    <textarea name="content" id="content" cols="50" rows="5"></textarea>
    <input type="submit" name="Submit" value="提交" /><BR>
    注: 发图片的格式为 < img src="http:// 图片的网址 " >
    </label>

</form>
<!--
<form id="form2" name="pagesize" method="post" action="add.php">
  <label></label>
  <label>每页显示
  <input type="text" name="pagesize" size="4" />条
  </label>
</form>-->
<table width="700" border="1" align="center">


  <?php

  setcookie("pagesi",$_POST[pagesize]);
  $pagesize=8;

  $url=$_SERVER["REQUEST_URI"];  // 显示:/bbs/add.php
  $url=parse_url($url);  //Array ( [path] => /bbs/add.php )
  $url=$url[path];  ///bbs/add.php

  $numa=mysql_query("select * from newsay");
  $num=mysql_num_rows($numa); //数据库中多少条信息

   if($_GET[page])
{
     $pageval=$_GET[page];
     $page=($pageval-1)*$pagesize;
     $page.=',';
}
if($num>$pagesize)
{
    if ($pageval<=0) $pageval=1;
    $pagecon=ceil($num/$pagesize);
echo "共 <font color=#0033FF> $num </font> 条 ,",$pagecon." 页 当前为第<font color=#0033FF> $pageval </font> 页 ";
        if($pageval>1)
        {
            echo " <a href=$url?page=".($pageval-1).">上一页</a> ";
        }
        if($pageval*$pagesize<$num)
        {
            echo "<a href=$url?page=".($pageval+1)."> 下一页 </a>";
        }
}

  $sqll="select * from newsay order by id desc limit $page $pagesize";
  $qu=mysql_query($sqll);
  while($row=mysql_fetch_array($qu)){
  ?>
  <tr>
    <td><span class="STYLE1">姓名: </span><?php echo $row[name] ?></td>
    <td><span class="STYLE1">性别: </span><?php echo $row[sex] ;
    if($row[sex]!='男' & $row[sex]!='女')
    echo '<span class="STYLE1">唔讲你知</span>'; ?></td>
    <td><span class="STYLE1">时间: </span><?php echo $row[time] ?></td>
  </tr>
  <tr>
    <td colspan="3"><span class="STYLE1">内容: </span><?php echo htmltocode($row[content]) ?><br></td>
    <?php
  }
  ?>
  </tr>
</table>
</body>
</html>
[/php]
[ 此帖被落伍在2008-11-11 10:42重新编辑 ]

作者: dreac   发布时间: 2008-11-10

能不能打包啊~发表也没有使用PHP标签,扣分~

作者: 落伍   发布时间: 2008-11-11

引用
引用第1楼落伍于2008-11-11 10:40发表的  :
能不能打包啊~发表也没有使用PHP标签,扣分~

。。。

作者: shikey   发布时间: 2008-11-11

。。。。。。。
还是打个包好点

作者: sclzwj   发布时间: 2009-03-08

up up

作者: sclzwj   发布时间: 2009-03-18

还有待提高哦啊

作者: wjp_lhc   发布时间: 2009-03-26

热门下载

更多