发表公告首页代码如下:
<body>
<form id="form1" name="form1" method="post" action="affiche.php">
  <table width="200" border="0" align="center">
    <tr>
      <td>公告主题:
        <input type="text" name="textfield" id="txt_title" /></td>
    </tr>
    <tr>
      <td>公告内容:
        <textarea name="txt_content" cols="50" rows="8" id="txt_content"></textarea></td>
    </tr>
    <tr>
      <td align="center"><label>
        <input type="submit" name="button" id="button" value="保存" onClick = "return check(form1)">
        <input type="reset" name="button2" id="button2" value="重置" >
      </label></td>
    </tr>  </table>
</form>
<script language="javascript">
function check (form){
    if(form.txt_title.value==""){
        alert("请输入公告标题!");
        form.txt_title.focus();
        return false;
        }
        if(form.txt_content.value==""){
            alert("请输入公告内容!");
            form.txt_content.focus();
            return false;
            }
            form.submit();
    }
    </script>
</body>
跳转到的连接数据库显示页面代码如下:
<body>
<table width="727" border="0" align="center">
  <tr>
    <td width="205" align="center">标题</td>
    <td width="401" align="center">内容</td>
    <td width="99" align="center">时间</td>
  </tr>
<?php 
$conn = mysql_connect("localhost","root","406297671");
mysql_select_db("0135",$conn);
mysql_query("set names gb3212");
$sql = mysql_query("select * form guest order by title,content,createtime",$conn);
$title = $_POST[txt_title];
$content = $_POST[txt_content];
$createtime = date("Y-m-d H:i:s");
$sql = mysql_query("insert into guest(title,content,createtime)values('$title','$content','$createtime')");
echo"<script>alert('');window.location.href = add_affiche.php';</script>
mysql_free_result($sql);
mysql_close($conn);
$info = mysql_fetch_array($sql);
if ($info ==false)
     {
     echo "暂无公告信息!";                                    //第30行出现错误的地方      
    }else   {
         do
         {
?>
  <tr>
    <td><?php echo $info[title];?></td>
    <td><?php echo $info[content];?></td>
    <td><?php echo $info[createtime];?></td>
  </tr>
  <?php 
         }
         while($info = mysql_fetch_array($sql));
     }
  ?>
以下是点击提交按钮后出现的错误:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in E:\APMServ-v5.2.6\APMServ5.2.6\www\htdocs\affiche.php on line 30
望高人帮小弟排忧解难!!!不甚感谢!!! 

解决方案 »

  1.   

    echo"<script>alert('');window.location.href = 'add_affiche.php';</script>";//是不是这句有问题。
      

  2.   

    echo"<script>alert('');window.location.href = add_affiche.php';</script>";//少了结束另外
    $sql = mysql_query("select * form guest order by title,content,createtime",$conn);
    $sql = mysql_query("insert into guest(title,content,createtime)values('$title','$content','$createtime')");
    两个 $sql 冲突,将对后续的
    $info = mysql_fetch_array($sql);
    产生错误
      

  3.   

    另外
    $sql = mysql_query("select * form guest order by title,content,createtime",$conn);
    $sql = mysql_query("insert into guest(title,content,createtime)values('$title','$content','$createtime')");
    两个 $sql 冲突,将对后续的
    $info = mysql_fetch_array($sql);
    产生错误
    那这里要怎么改,麻烦你能不能帮我解释的详细点,我没怎么理解你的观点.....
      

  4.   

    mysql_query("insert into guest(title,content,createtime)values('$title','$content','$createtime')"); //直接去掉变量名。
      

  5.   

    我现在该成这样了可还是不成:
    <?php 
     $conn = mysql_connect("localhost","root","406297671");
     mysql_select_db("0135",$conn);
     mysql_query("set names gb3212");
     mysql_query("insert into guest(title,content,createtime)values('$title','$content','$createtime')");
     echo"<script>alert('');window.location.href = add_affiche.php';</script>";
     $sql = mysql_query("select * form guest order by title,content,createtime",$conn);
     $title = $_POST[txt_title];
    $content = $_POST[txt_content];
    $createtime = date("Y-m-d H:i:s");$mysql_result = mysql_free_result($sql); $info = mysql_fetch_array($sql_result);
     if ($info ==false)
         {
     echo "暂无公告信息!";
     }
     else{
     do
     {
     ?>
      <tr>
        <td><?php echo $info[title];?></td>
        <td><?php echo $info[content];?></td>
        <td><?php echo $info[createtime];?></td>
      </tr>
      <?php 
     }while($info = mysql_fetch_array($sql));
     }
    mysql_close($conn);
      ?>
      

  6.   

     echo"<script>alert('');window.location.href = 'add_affiche.php';</script>";
    少一个  还是不行 什么问题
      

  7.   

    现在是这样的,我有两个页面一个是如下:另外一个是:在数据库中建有一张名为‘guset’的表里面的字段分别是'title','content','createtime',现在是要把输入在第一个页面里的内容输入到数据库并直接且跳转到第二个页面中,第二个页面为“affiche.php”,我所发的程序就是想达到该目的的.....望高人帮我写一个能达到此目的的程序,小弟非常感谢!!!!
      

  8.   

    去掉 $mysql_result = mysql_free_result($sql);
      

  9.   

    你好,要是按照你这样说去掉 $mysql_result = mysql_free_result($sql);这个的话那下面的
    $info = mysql_fetch_array($mysql_result); //这个调用变量$mysql_result就没用了!!!
     if ($info ==false)
      {
    echo "暂无公告信息!";
    }
    else{
    do
    {
     ?>
      <tr>
      <td><?php echo $info[title];?></td>
      <td><?php echo $info[content];?></td>
      <td><?php echo $info[createtime];?></td>
      </tr>
      <?php  
    }while($info = mysql_fetch_array($sql));
    }
    mysql_close($conn);
      

  10.   


    <?php 
     $conn = mysql_connect("localhost","root","406297671");
     mysql_select_db("0135",$conn);
     mysql_query("set names gb3212");
     mysql_query("insert into guest(title,content,createtime)values('$title','$content','$createtime')");
     echo"<script>alert('保存成功');window.location.href = 'affiche.php';</script>";//来点提示信息多好啊。
     $sql = mysql_query("select * form guest order by title,content,createtime",$conn);//这是什么。根据三个排序?
     $title = $_POST[txt_title];
    $content = $_POST[txt_content];
    $createtime = date("Y-m-d H:i:s");
     $num = mysql_num_rows($sql);
     if ($num>0)
      {
    while($info = mysql_fetch_array($sql)){echo '<tr>';
      echo '<td> '.$info[title].'</td>';
      echo '<td>'.$info[content].'</td>';
      echo '<td>' .$info[createtime].'</td>';
    echo '</tr>';
    }
    }
    else{
       echo "暂无公告信息!";
    }
    mysql_close($conn);还有你本身表就没设计好。没自增的id字段。主键又是哪个字段。
      

  11.   

    明显是sql语句写错了。select * form guest order by title,content,createtime红色的必须是from 而不是form 啊.
      

  12.   

    <body>
    <table width="727" border="0" align="center">
      <tr>
        <td width="205" align="center" bgcolor="#FF0000">标题</td>
        <td width="401" align="center" bgcolor="#FF0000">内容</td>
        <td width="99" align="center" bgcolor="#FF0000"> 时间</td>
      </tr>
      
     <?php 
     
     $conn = mysql_connect("localhost","root","406297671");
     mysql_select_db("0135",$conn);
     mysql_query("set names utf8");
    $title = $_POST[txt_title];
    $content = $_POST[txt_content];
    $createtime = date("Y-m-d H:i:s");
     mysql_query("insert into guest(title,content,createtime)values('$title','$content','$createtime')");echo"<script>alet('保存成功');.window.location.href='affiche.php';</script>"; 
     $sql = mysql_query("select * from guest order by title,content,createtime");
     
     @$num = mysql_fetch_array($sql);
     ?>
    <tr>
         <td width="205" align="center" bgcolor="#0000FF"><?php echo $num->title;?></td>
         <td width="205" align="center" bgcolor="#0000FF"><?php echo $num->content;?></td>
         <td width="205" align="center" bgcolor="#0000FF"><?php echo $num->createtime;?></td>
      </tr>
    </table>
    </body>
    </html>
      

  13.   

    $num = mysql_fetch_array($sql);
     ?>
    <tr>
         <td width="205" align="center" bgcolor="#0000FF"><?php echo $num->title;?></td>你用 mysql_fetch_array 返回的是数组,怎么能用对象($num->title)访问到呢?要不 mysql_fetch_array 改为 mysql_fetch_object
    要不 $num->title 改为 $num['title']
    两者不能混用
      

  14.   

    按照你说的我改过了现在改过了 
    $sql = mysql_query("select * from guest ");
     
     $info = mysql_fetch_object($sql);
    ?>
    <tr>
         <td width="205" align="center" bgcolor="#0000FF"><?php echo $info->title;?></td>
         <td width="205" align="center" bgcolor="#0000FF"><?php echo $info->content;?></td>
         <td width="205" align="center" bgcolor="#0000FF"><?php echo $info->createtime;?></td>
      </tr>
      
       <?php
    现在也能在跳转到的页面看到数据库里面的信息了,是这样的只能在页面中显示一条数据库中的信息,其他添加进去的数据显示不了这里用什么方法能做到,让表格自动增长,把所添加的数据都显示出来....
      

  15.   

     while($info = mysql_fetch_object($sql)){
    ?>
    <tr>
         <td width="205" align="center" bgcolor="#0000FF"><?php echo $info->title;?></td>
         <td width="205" align="center" bgcolor="#0000FF"><?php echo $info->content;?></td>
         <td width="205" align="center" bgcolor="#0000FF"><?php echo $info->createtime;?></td>
      </tr>
      
       <?php 
    }
    ?>
    //加个循环试试。
      

  16.   

    好了现在把调试好的代码放上来.....有什么需要改正的地方大家都来拍砖....
    <!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" />
    <title>无标题文档</title>
    </head><body>
    <table width="727" border="0" align="center">
      <tr>
        <td width="205" align="center" bgcolor="#FF0000">标题</td>
        <td width="401" align="center" bgcolor="#FF0000">内容</td>
        <td width="99" align="center" bgcolor="#FF0000"> 时间</td>
      </tr>
      
     <?php 
     
     $conn = mysql_connect("localhost","root","406297671");
     mysql_select_db("0135",$conn);
     mysql_query("set names utf8");
    $title = $_POST['title'];  
    $content = $_POST['content'];
    $createtime = date("Y-m-d H:i:s");
     mysql_query("insert into guest(title,content,createtime)values('$title','$content','$createtime')");echo"<script>alet('保存成功');.window.location.href='affiche.php';</script>"; //来点提示信息多好啊。
     $sql = mysql_query("select * from guest ");//查找数据库'0135'中的表'guest'
     
     $info = mysql_fetch_object($sql);//mysql_fetch_object() 函数从结果集(记录集)中取得一行作为对象
     if($info){
     do{
     
     ?>
    <tr>
         <td width="205" align="center" bgcolor="#33CCFF"><?php echo $info->title;?></td>
         <td width="205" align="center" bgcolor="#33CCFF"><?php echo $info->content;?></td>
         <td width="205" align="center" bgcolor="#33CCFF"><?php echo $info->createtime;?></td>
      </tr>
      <?php
         
    }while($info = mysql_fetch_object($sql));//条循环语句
      }
      mysql_close($conn);//最后关闭数据库连接
      ?>
       
    </table>
    </body>
    </html>