本人菜鸟做的一个简单的留言本。数据插入功能可以实现。但是显示不出来库里的数据。以下是代码:
/******** conn.php ********/
$conn= @ mysql_connect("localhost","root","") or die("数据库连接错误".mysql_error());
mysql_select_db("message",$conn);
mysql_query("set names gb2312");
/******** liuyan.php **********/
<?php
include("conn.php"); if($_POST['submit']){
$sql="insert into message (id,user,title,content,lastdate)" .
" values('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);
echo"发表成功";
}
?>
<form action="file.php" method="post">
用 户:
<input type="text" name="user" value="" size="10" maxlength="40"/><br>
标 题:
<input type="text" name="title" value=""size="20" maxlength="40"/><br>
内 容:
<textarea name="content" rows="10" cols="30" ></textarea><br>
<input type="submit" name="submit" value="发表留言"/>
</form>/********* show.php ***********/
<?php
include("conn.php");
?> <table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<?
$sql="select * from message";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){?>
<tr bgcolor="#eff3ff">
<td>标题:<?=$row[title]?> 用户:<?=$row[user]?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?=$row[content]?></td>
</tr>
<?
}
?>
</table>
/******** conn.php ********/
$conn= @ mysql_connect("localhost","root","") or die("数据库连接错误".mysql_error());
mysql_select_db("message",$conn);
mysql_query("set names gb2312");
/******** liuyan.php **********/
<?php
include("conn.php"); if($_POST['submit']){
$sql="insert into message (id,user,title,content,lastdate)" .
" values('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);
echo"发表成功";
}
?>
<form action="file.php" method="post">
用 户:
<input type="text" name="user" value="" size="10" maxlength="40"/><br>
标 题:
<input type="text" name="title" value=""size="20" maxlength="40"/><br>
内 容:
<textarea name="content" rows="10" cols="30" ></textarea><br>
<input type="submit" name="submit" value="发表留言"/>
</form>/********* show.php ***********/
<?php
include("conn.php");
?> <table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<?
$sql="select * from message";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){?>
<tr bgcolor="#eff3ff">
<td>标题:<?=$row[title]?> 用户:<?=$row[user]?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?=$row[content]?></td>
</tr>
<?
}
?>
</table>
你的PHP有没有设置 短标签 如果没有的话 用<?... ?>是不可以的,要用<?php....?>才会显示出来不知道加上后可不可以,你可以试一下<?php
include("conn.php");
?><table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef"><?php$sql="select * from message";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){?>
<tr bgcolor="#eff3ff">
<td>标题:<?php=$row[title]?> 用户:<?php=$row[user]?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?php=$row[content]?></td>
</tr><?php
}
?>
</table>
<tr bgcolor="#eff3ff">
<td>标题:<?php=$row[title]?> 用户:<?php=$row[user]?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?php=$row[content]?></td>
</tr>
@mysql_connect("localhost","root","") or die("数据库连接错误".mysql_error());
@mysql_select_db("message") or die("数据库选择错误".mysql_error());
mysql_query("set names 'gb2312'");
/******** liuyan.php **********/
<?php
include("conn.php");if($_POST['submit']){
$sql="insert into `message` (`user`,`title`,`content`,`lastdate`)" .
" values('$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);
echo"发表成功";
}
?>
<form action="liuyan.php" method="post">
用 户:
<input type="text" name="user" value="" size="10" maxlength="40"/><br>
标 题:
<input type="text" name="title" value=""size="20" maxlength="40"/><br>
内 容:
<textarea name="content" rows="10" cols="30" ></textarea><br>
<input type="submit" name="submit" value="发表留言"/>
</form>/********* show.php ***********/
<?php
include("conn.php");
?><table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<?php
$sql="select * from message";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){?>
<tr bgcolor="#eff3ff">
<td>标题:<?php echo $row['title'];?> 用户:<?php echo $row['user'];?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?php echo $row['content'];?></td>
</tr>
<?php
}
?>
</table>
报错还是仅仅
$sql="select * from message";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){
******//这里的内容没显示出来?
}
最好把你的conn那个文件贴出来,让大家找下错误
mysql_query("SET NAMES UTF-8");
然后看你的数据库是什么格式的还有你的页面开始的时候加上<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>标准点