日期:2014-05-17  浏览次数:20698 次

PHP100视频教程第11讲 正确代码
conn.php 文件
<?php
$conn = @ mysql_connect("localhost", "root", "") or die("数据库链接错误");
mysql_select_db("newdb", $conn);
mysql_query("set names 'GBK'"); //使用GBK中文编码;
?>

add.php 文件
<?php
include ("conn.php");
if(isset($_POST['submit']) && $_POST['submit']) //吧if($_post['submit'])替换矫正Notice: Undefined index: submit in 错误
{
$sql_add="insert into message (id,user,title,content,lastdate) values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql_add);
echo "发表成功";
}
?>
<form action="add.php" method="post">
用户:<input type="text" name="user" value="" size="40" maxlength="40"/><br/>
  标题:<input type="text" name="title" value="" size="40" maxlength="40"/><br/>
  内容:<textarea name="content" rows="10" cols="50" ></textarea><br/>
  <input type="submit" name="submit" value="发布留言"/>
</form>
list.php 文件
<?php
include("conn.php");
?>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
 <?php
  $sql_list="SELECT * FROM message order by id desc";
  $query=mysql_query($sql_list);
  while($row=mysql_fetch_array($query)){
  ?>
  <tr bgcolor="#eff3ff">
//$row[]里面的参数用单引号扣起来
  <td>标题:<?=$row['title']?> 用户:<?=$row['user']?></td>
  </tr>
  <tr bgColor="#ffffff">
  <td>内容:<?=$row['content']?></td>
  </tr>
  <?php
}
  ?>
</table>

------解决方案--------------------
你有什么问题呀。。。不明白你问的。