包袱里有抱负 2015-12-10 14:48 采纳率: 0%
浏览 1564
已采纳

新学的PHP,但还是不会连接数据库,有个小问题

问一下怎么建立数据库呢?登陆时已经可以完成的了,就是留言功能不能实现
这是用户的注册
这是留言板,这个是不能实现的

 <head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>留言板</title>
</head>

<div> <a href='denglu.php'>返回</a></div>

<?php
error_reporting(E_ALL &~ E_NOTICE);
session_start(); 
$con = mysql_connect("localhost","root","");  

if (!$con)  
  {  
  die('Could not connect: ' . mysql_error());  
  }  else echo"<br>connected!<br>";


  $selected = mysql_select_db("center" ) ;
//if($selected)
//echo"selected!<br>";

mysql_query("set names 'utf8'");

$insert_account = $_SESSION['account'];
$insert_pwd = $_SESSION['password'];
echo $insert_account;

//echo $_POST[comment];
if($_SESSION['check'] ==1){
if(!empty($_POST[comment]) )
{
$sql="INSERT INTO comment (account,comment,time)VALUES('$insert_account','$_POST[comment]','$printtime')";  
mysql_query($sql) or die(mysql_error());
$_SESSION['check'] = 0;
}else echo '<div align="center"><font color = "red" font size = 50>欢迎来到留言板</font>' ;
}
$insert_account
?>
<div align="center">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div valign="center">请留言 </div>
 <textarea  name="comment" rows="5" cols="40" ><?php 
//echo readfile("webdictionary.txt");
?></textarea>

<tr><input type="submit" name="submit" value="提交" /></tr>

<p>您已提交的留言:</p>
<hr>

<?php 


$pagesize=10;
mysql_select_db("center") or die("no");
//取得记录总数$rs,计算总页数用
$rs=mysql_query("select count(*) from comment");
$myrow = mysql_fetch_array($rs);
$numrows=$myrow[0];
echo "总留言数量:".$numrows;
//计算总页数
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
$pages++;
//设置页数
if (isset($_GET['page'])){
$page=intval($_GET['page']);
}
else{
//设置为第一页 
$page=1;
}
//计算记录偏移量
$offset=$pagesize*($page - 1);
//读取指定记录数
$rs=mysql_query("select * from comment order by ID desc limit $offset,10");//$offset,
if ($myrow = mysql_fetch_array($rs))
{ 
$i=0;
?>
<table border="0" width="100%">
<tr>
<td  width="50%" bgcolor="#E0E0E0">
    <p align="center">留言</td>
<td width="20%" bgcolor="#E0E0E0">
    <p align="center">发布时间</td>
<td width="20%" bgcolor="#E0E0E0">
    <p >留言用户</td>
  </tr>
  <?php
   do {
    $i++;
    ?>
  <tr>
   <td width="50%"><?php echo $myrow["comment"] ?></td>
   <td width="20%"><?php echo $myrow["time"] ?></td>
    <td width="20%"><?php echo $myrow["account"] ?></td>
  </tr>
   <?php
   }
   while ($myrow = mysql_fetch_array($rs));
    echo "</table>";
  }
  echo "<div align='center'>共有".$pages."页(".$page."/".$pages.")";
  for ($i=1;$i< $page;$i++)
   echo "<a href='comment.php?page=".$i."'>[".$i ."]</a> ";
   echo "[".$page."]";
   for ($i=$page+1;$i<=$pages;$i++)
    echo "<a href='comment.php?page=".$i."'>[".$i ."]</a> ";
    echo "</div>";
   ?>
<br><br><br>
</body>
 <!--  <script src="/javascript/myScript.js"  charset="utf-8"> </script>   -->




</html>
  • 写回答

3条回答 默认 最新

  • threenewbee 2015-12-10 15:11
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条