Home  >  Article  >  Backend Development  >  php-新学的PHP,但还是不会连接数据库,有个小问题

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

WBOY
WBOYOriginal
2016-06-02 11:29:12768browse

php数据库

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

<code> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>留言板</title>
<div> <a href="denglu.php">返回</a>
</div>
<?phperror_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%20echo%20htmlspecialchars(%24_SERVER%5B" 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">留言</p>
</td>
<td width="20%" bgcolor="#E0E0E0">    <p align="center">发布时间</p>
</td>
<td width="20%" bgcolor="#E0E0E0">    <p>留言用户</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[".$i ."] ";   echo "[".$page."]";   for ($i=$page+1;$i[".$i ."] ";    echo "</div>";   ?><br><br><br>
</table>
</form></div>
</div></code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn