+ -
当前位置:首页 → 问答吧 → Notice: Undefined index: submit in *

Notice: Undefined index: submit in *

时间:2010-08-29

来源:互联网

在调试php程序时出现Notice: Undefined index: submit in D:\www\chat\add.php on line 26
并且<?php=$row[username]?>,<?php=$row[utitle]?>,<?php=$row[ucon]?>,<?php=$row[remake]?>现实不出来。

请高手指点,以下是源码:

----这个提交页面----
<?php
 include("conn.php");
 if($_POST['submit']){
  $sql="insert into chat (id,username,utitle,ucon,remake) values ('','$_POST[username]','$_POST[utitle]','$_POST[ucon]',now())";
  mysql_query($sql);
  echo"发表成功";
 }
?>
 <div id="wrap">
  <h1>添加留言</h1>
  <form action="add.php" method="post">
  <table cellpadding="0" cellspacing="1" class="Table">
   <tr>
    <th>用户名:</th>
    <td><input name="username" type="text" class="input" /></td>
   </tr>
   <tr>
    <th>标题:</th>
    <td><input name="utitle" type="text" class="input" /></td>
   </tr>
   <tr>
    <th valign="top">内容:</th>
    <td><textarea name="ucon" type="text" /></textarea></td>
   </tr>
   <tr>
    <td colspan="2" align="center"><input name="submit" type="submit" value="提交" class="btn" /></td>
   </tr>
  </table>
  </form>
 </div>

----这是现实页面---
<?php
  include("conn.php");
 ?>
  <h1>留言板</h1>
  <?php
   $sql="select * from chat";
   $query=mysql_query($sql);
   while ($row=mysql_fetch_array($query)){
   
  ?>
  <dl>
   <dt>标题:<?php=$row[utitle]?><span>用户名:<em><?php=$row[username]?></em>时间:<?php=$row[remake]?></span></dt>
   <dd><?php=$row[ucon]?></dd>
  </dl>
  <?php
   } 
  ?>

作者: hunkin007   发布时间: 2010-08-29

你这样的写法应该是<?=$row['utitle']?>而且要从php.ini里,吧short_open_tag设为On
或者,老老实实写<?php echo $row['utitle'];?>
至于那个notice如果不想看到,可以在开始处设置error_reporting(E_ERROR | E_WARNING | E_PARSE);

作者: tochenwei   发布时间: 2010-08-29

引用
引用第1楼tochenwei于2010-08-29 12:31发表的  :
你这样的写法应该是<?=$row['utitle']?>而且要从php.ini里,吧short_open_tag设为On
或者,老老实实写<?php echo $row['utitle'];?>
至于那个notice如果不想看到,可以在开始处设置error_reporting(E_ERROR | E_WARNING | E_PARSE);


<?php echo  $a?>或<?=$a?>你写错了。NOTICE没影响。

作者: element   发布时间: 2010-08-29