+ -
当前位置:首页 → 问答吧 → 关于include的用法

关于include的用法

时间:2010-01-09

来源:互联网

下面这段执行是没有问题的
<?php
error_reporting(E_ALL & ~E_NOTICE);
$conn = @ mysql_connect("localhost","root","12") or die("链接错误");
mysql_select_db("newdb",$conn);
mysql_query("set names 'gbk'");
if($_POST['submit']){
$sql="insert into message (id,user,title,content,lastdate)" .
         " values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);
echo "发布成功";
}

?>
  <form action="add.php" method="post">
  用户名:<input type="text" name="user" size="40" /><br>
  标题:<input type="text" name="title" size="40" /><br>
留言内容:<br> <textarea name="content" >
  </textarea><br>
  <input type="submit" name="submit" value="发布留言"/>
  </form>
[ 此帖被shi183在2010-01-09 17:21重新编辑 ]

作者: shi183   发布时间: 2010-01-09

但是在分开之后出现问题了,为什么啊,请指教,谢谢
第一个1.php:(连接成功)
<?php
    
    $user = "root";
    $passwd = "12";
    
    
    $connect = mysql_connect('localhost', $user, $passwd)
       or die('数据库连接失败 ');
    echo '<BR><b>第一步:</b>成功建立连接! <BR>';
    
    $db = 'newdb';
    mysql_select_db($db) or die('Could not select database');
    echo '<b>第二步:</b> 成功连接到 ('.$db.')!<BR>';
    
    
    mysql_close($connect);
?>
第二个2.php:(显示Parse error: parse error in D:\wamp\www\TMP6prbgvyw7b.php on line 23) 也就是最后一行  </form>
<?php
include("1.php");
?>
<?php
error_reporting(E_ALL & ~E_NOTICE);
if($_POST['submit']){
$sql="insert into message (id,user,title,content,lastdate)" .
         " values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);        
echo"成功";
?>
  <form action="2.php" method="post">

  用户名:<input type="text" name="user" size="40" /><br>
  标题:<input type="text" name="title" size="40" /><br>

留言内容:<br> <textarea name="content" >

  </textarea><br>

  <input type="submit" name="submit" value="发布留言"/>

  </form>

作者: shi183   发布时间: 2010-01-09

你的2.php在if判断的时候少了一个 “}”

作者: ycg520520   发布时间: 2010-01-09

非常感谢,是我大意了

作者: shi183   发布时间: 2010-01-09