我为一个有3个不同php页面的网站创建了一本留言簿,在有人在留言簿上提交评论后,我无法查看文本。以下是每个
guestbook.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> </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> </td>
<td> </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> </td>
</tr>
</table>adressbook.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();
?>viewguestbook.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> </p>如果有人能帮忙的话?另外,我,评论的顺序是上升的,我想显示它们下降吗?
发布于 2013-06-18 05:25:38
将其更改为降序变化。
$sql="SELECT * FROM $tbl_name";至
$sql="SELECT * FROM guestbook ORDER BY datetime DESC";我不知道你所说的“我不能看课文”是什么意思。这是否意味着您的guestbook 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-18 05:39:47
<?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.phphttps://stackoverflow.com/questions/17161007
复制相似问题