<?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>这段代码为什么取不出数据????
$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>这段代码为什么取不出数据????
$sql="select * from message";
$query=mysql_query($sql);
while($row = mysql_fetch_array($query)){
?> ?????????????php呢<?php
谢谢你!!!第一是按PHP的标准写法.<?php.....?>
第二是在配置文件中(php.ini)修改short_open_tag的值为on.
$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> <?
//字段名要引号
}