帮我看看,为什么取不出数据?

sssschenyi 2009-10-16 01:43:47
<?php
$conn = @ mysql_connect("localhost", "root", "root") or die("数据库链接错误");
mysql_select_db("bbs",$conn);
mysql_query("set names 'GBK'");

if($_POST['submit']){
$sql="insert into message values('','$_POST[user]','$_POST[title]','$_POST[content]',now())"; mysql_query($sql);
echo 'insert OK';
}
?>

<form action='add.php' method='post' >
用户:<input type='text' name='user' ><br>
标题:<input type='text' name='title' ><br>
内容:<textarea name='content'></textarea></br>

<input type='submit' name='submit' value='提交' />

</form>
这段代码能插入数据。我插入了N条数据了!!就是取不出来?帮我看看下面的代码??


<?php
$conn = @ mysql_connect("localhost", "root", "root") or die("数据库链接错误");
mysql_select_db("bbs",$conn);
mysql_query("set names 'GBK'");
?>

<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>

这段代码为什么取不出数据????

...全文
107 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sssschenyi 2009-10-16
  • 打赏
  • 举报
回复
1 楼 正解!!thanks !
dzxccsu 2009-10-16
  • 打赏
  • 举报
回复

$conn = @ mysql_connect("localhost", "root", "root") or die("数据库链接错误");
mysql_select_db("bbs",$conn);
mysql_query("set names GBK");//不用引号
?>

<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>

<?
//字段名要引号
}

sssschenyi 2009-10-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zhoupuyue 的回复:]
短标记开启了没?
[/Quote]

谢谢你!!!

第一是按PHP的标准写法.<?php.....?>
第二是在配置文件中(php.ini)修改short_open_tag的值为on.
fangle_life 2009-10-16
  • 打赏
  • 举报
回复
你这样写没报错么?你的 "$row[title]" $row 中的那个 “title” 要加上 引号。
「已注销」 2009-10-16
  • 打赏
  • 举报
回复
<?
$sql="select * from message";
$query=mysql_query($sql);
while($row = mysql_fetch_array($query)){
?>



?????????????php呢

<?php
阿_布 2009-10-16
  • 打赏
  • 举报
回复
短标记开启了没?

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧