留言板问题求助
先问一个关于乱码的问题,
在my.ini中设置了 [client] default-character-set=utf8 [mysqld] default-character-set=utf8 然后重启wamp,phpmyadmin就连接不上了,就是#2002 那个套接字错误提示,然后我就把my.ini刚做的修改又改了回去,还是连接不上,(我把修改撤销了应该可以了呀??问题1)最后把localhost改为127.0.0.1 才恢复正常
问题二: 上述操作之后
最后问题
1、conn文件
<?php
$conn = mysql_connect("localhost","root","") or die("Can't connect database: ".mysql_error());
if($conn)
echo "链接成功!";
mysql_select_db("liuyan");
mysql_query("set names 'gbk'");
?>
<form name = "msgform" method = "post" action = "write.php" enctype = "multipart/form-data" onsubmit = "return checkMessage()">
//javascript略去了
<table width = "64%" border = "0" cellspacing = "1" cellpadding = "3" bgcolor = "#66CCFF" align = "center">
<tr>
<td width = "48%">用 户:
<input type = "txet" name = "username">
</td>
</tr>
<tr>
<td colspan = "2">标 题:
<input type = "text" name = "title" size = "60" maxlength = "50">
</td>
</tr>
<tr>
<td colspan = "2">
<textarea name = "content" rows = "10" cols = "100"></textarea>
</td>
</tr>
<tr>
<td>
<div align = "right">
<input type = "submit" name = "sub" value = "提交">
</div>
</td>
<td>
<input type = "reset" name = "Rewrite" value = "重写">
</td>
</tr>
</table>
</form>
<?php
include("conn.php");
if(isset($_POST['username'])){
$username = $_POST['username'];
$title = $_POST['title'];
$content = $_POST['content'];
$sql = "insert into easy values('$username','$title','$content',now())";
mysql_query($sql) or die("插入失败: ".mysql_error());
}
?>
<?php
include("conn.php");
$rowsPerPage = 10;
$row = mysql_fetch_array(mysql_query("select count (*) as c from easy")); //查询总记录数...这点书上看的,不太懂,求解释
$rows = $row['c']; //得到记录数
/*
$a = "select * from easy";
$b = mysql_query($a);
$rows = mysql_num_rows($b);
这个可以么? 另外这个和上面那个有什么区别??
*/
$pages = ceil($rows/$rowsPerPage); //计算页数
$curPage = 1;
if(isset($_REQUEST['curPage']))
$curPage = $_REQUEST['curPage'];
$sql = "select * from easy order by posttime" ." limit ".($curPage - 1) * $rowsPerPage." ,$rowsPerPage";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo "<table width = 90% align=center cellpadding=5 cellspacing=1 bgcolor=blue>";
echo "<tr>";
echo "<td rowspan = 2 width = 25% bgcolor = white>";
echo "<tr>标题:<?=$row[title]?></tr>";
echo "<li>用户:<?=$row[username]?>";
echo "<li> <?= $row[posttime]?>";
echo "</td>";
echo "<td>内容:<?= $row[content]?></td>";
echo "</tr>";
echo "</table>";
echo "<br>";
}
//分页链接
echo "<div align = center>";
for($i = 1;$i<$pages;$i++)
echo "<a href = 'write.php?curPage = $i'>$i</a>$nbsp; ";
echo "</div>";
?>