0

我为一个有 3 个不同 php 页面的网站创建了一个留言簿,在有人对留言簿提交评论后,我无法查看文本.. 这是每个的编码


留言簿.php


<style type="text/css">
body,td,th {
    color: #FFFFFF;
}
body {
    background-color: #333333;
}
a:link {
    color: #FFFFFF;
}
a:visited {
    color: #FFFFFF;
}
a:hover {
    color: #FFFFFF;
}
a:active {
    color: #FFFFFF;
}
</style>
<body bgcolor="#333333" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">    <table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td>&nbsp;</td>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" >
<tr>
<form id="form1" name="form1" method="post" action="addguestbook.php">
<td>
<table width="400" border="0" cellpadding="3" cellspacing="1" >
<tr>
<td width="117">Name</td>
<td width="14">:</td>
<td width="357"><input name="name" type="text" id="name" size="40" /></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="email" size="40" /></td>
</tr>
<tr>
<td valign="top">Comment</td>
<td valign="top">:</td>
<td><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="  Sign  " /> <input type="reset"      name="Submit2" value="Reset" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td>&nbsp;</td>
</tr>
</table>

地址簿.php


<style type="text/css">
body,td,th {
    color: #FFF;
}
body {
    background-color: #333333;
}
a:link {
    color: #FFF;
}
a:visited {
    color: #FFF;
}
a:hover {
    color: #FFF;
}
a:active {
    color: #FFF;
}
</style>
<body bgcolor="#333333" text="#FFF" link="#FFF" vlink="#FFF" alink="#FFF"><?php
$host="*********"; // Host name 
$username="***********"; // Mysql username 
$password="***********!"; // Mysql password 
$db_name="***********"; // Database name 
$tbl_name="guestbook"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 
mysql_select_db("$db_name")or die("cannot select DB");

$datetime=date("y-m-d h:i:s"); //date time

$sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email',     '$comment', '$datetime')";
$result=mysql_query($sql);

//check if query successful 
if($result){
echo "Successful";
echo "<BR>";

}

else {
echo "ERROR";
}
mysql_close();
?>

访客留言簿.php


<?php

$host="*********"; // Host name 
$username="******"; // Mysql username 
$password="*****!"; // Mysql password 
$db_name="******"; // Database name 
$tbl_name="guestbook"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
?>
<style type="text/css">
body,td,th {
    color: #FFF;
}
body {
    background-color: #666;
}
a:link {
    color: #FFF;
}
a:visited {
    color: #FFF;
}
a:hover {
    color: #fff;
}
a:active {
    color: #FFF;
}
</style>


<table width="400" border="1" align="center" cellpadding="0" cellspacing="1" >
<tr>
<td><table width="400" border="0" cellpadding="3" cellspacing="1" >
<tr>
  <td width="117">Name</td>
  <td width="14">:</td>
  <td width="357"><? echo $rows['name']; ?></td>
</tr>
<tr>
  <td valign="top">Comment</td>
  <td valign="top">:</td>
  <td><? echo $rows['comment']; ?></td>
</tr>
<tr>
<td valign="top">Date/Time </td>
<td valign="top">:</td>
<td><? echo $rows['datetime']; ?></td>
</tr>
</table></td>
</tr>
</table>

<p>
  <?php
}
mysql_close(); //close database
?>
</p>
<p>&nbsp; </p>

如果有人可以帮忙吗?另外我评论的顺序显示升序我想显示他们降序?

4

2 回答 2

0
<?php

//change this line as

while($rows=mysql_fetch_assoc($result)){ .. }


mysql_fetch_array -- will always returns the indexed array.

//http://php.net/manual/en/function.mysql-fetch-array.php
于 2013-06-18T05:39:47.720 回答
0

将其更改为降序更改。

$sql="SELECT * FROM $tbl_name";

$sql="SELECT * FROM guestbook ORDER BY datetime DESC";

我不确定您所说的“我无法查看文本”是什么意思。这是否意味着您的留言簿 php 页面没有显示条目,或者数据库是空白的?

我不确定你为什么这样做$tbl_name = "guestbook";,但这只会让事情变得混乱。此外,您的空间到处都是,所以我不确定这是否是问题所在。

换个试试...

$sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email',     '$comment', '$datetime')";

进入

$sql="INSERT INTO guestbook (name, email, comment, datetime) VALUES ('$name', '$email', '$comment', '$datetime')";
于 2013-06-18T05:25:38.837 回答