php行中的错误

php行中的错误,php,html,Php,Html,一切正常。但问题是,当我添加新联系人时。页面不会返回索引,如果我返回索引,则会添加新联系人。我用一些检查软件检查了我的代码,它说我的PHP行有一个错误 <?php require_once"connection.php"; ?> <!DOCTYPE html> <html> <head> <?php include"includes/head.inc"; ?> <script>tinymce.init({

一切正常。但问题是,当我添加新联系人时。页面不会返回索引,如果我返回索引,则会添加新联系人。我用一些检查软件检查了我的代码,它说我的PHP行有一个错误

<?php
require_once"connection.php";
?>
<!DOCTYPE html>
<html>
  <head>
    <?php include"includes/head.inc"; ?>
    <script>tinymce.init({selector:'textarea'});</script>
  </head>
  <body>
    <div class="wrapper">
      <!-- header section -->
      <div class="header">
        <div class="headerContent"><h1>CONTACT LIST</h1></div>
      </div>
      <!-- content section -->
      <div class="content">
        <div><h1>Create New Contact</h1></div>
        <hr>
        <div class="contact">
          <div class="contact_insert">
            <form action="insert_contact.php" method="post">
              <table style="float:left" width="50%">
                <tr>
                    <td>Name:</td>
                    <td><input type="text" name="name" placeholder="name"  size="40%"></td>
                </tr>
                <tr>
                    <td>Email:</td>
                    <td><input type="text" name="email" placeholder="email" size="40%"></td>
                </tr>
                <tr>
                    <td>Department:</td>
                    <td><select name ="department" </td>
                </tr>
                <tr>
                    <td>Extension Number:</td>
                    <td><input type="text" name="extension" placeholder="extension" size="40%"></td>
                </tr>
                <tr>
                    <td>Cellphone:</td>
                    <td><input type="text" name="cellphone" placeholder="cellphone" size="40%"></td>
                </tr>
              </table>
              <div class="clear"></div>
              <input class="insert_contact_button" type="submit" name="submit" value="Add Contact">
              <a href="index.php"><input class="cancel_contact_button" type="button" value="Cancel"></a>
            </form>
          </div>
          <div class="clear"></div>
        </div>

  </body>
</html>
<?php
< ---IT SAYS THE ERROR IS HERE
if (isset($_POST['submit'])) {
  $name = $_POST['name'];
  $email = $_POST['email'];
  $department = $_POST['department'];
  $extension = $_POST['extension'];
  $cellphone = $_POST['cellphone'];
  $insert_contact = "insert into contacts (name, email, department, extension, cellphone) values ('$name', '$email', '$department', '$extension', '$cellphone')";
  $sql_insert_contact = $conn->query($insert_contact);
  $to = "manie@titan-networks.co.za";
  $from = "ExtensionList@alpinemotors.co.za";
  $subject = "New Staff Added To Extension List";
  $message = "New Staff: " . "\n\n" . "Name : " . $name . " " . "\n\n" . "Email: " . $email . " " . "\n\n" . "Department: " . $department . " " . "\n\n" . "Extension: " . $extension . " " . "\n\n" . "Cellphone: " . $
      $headers = "From:" . $from;
  mail($to, $subject, $message, $headers);
  if ($sql_insert_contact == true) {
    header("Location: index.php");
  }
}
?>

init({选择器:'textarea'});
联系人名单
创建新联系人

姓名: 电邮: 部门:
不能在html之后使用Header函数。 在渲染任何内容之前,将代码放到顶部

在发送任何实际输出之前,必须调用header(),可以通过文件中的正常HTML标记、空行或PHP调用。使用includerequire函数或其他文件访问函数读取代码,并且在调用header()之前输出空格或空行,这是非常常见的错误

<?php
    header("Location: index.php") //This will be succeed
?>
<html>
//some html
</html>
<?php
    header("Location: index.php") //This will fail
?>

//一些html

您不能在html之后使用头函数。 在渲染任何内容之前,将代码放到顶部

在发送任何实际输出之前,必须调用header(),可以通过文件中的正常HTML标记、空行或PHP调用。使用includerequire函数或其他文件访问函数读取代码,并且在调用header()之前输出空格或空行,这是非常常见的错误

<?php
    header("Location: index.php") //This will be succeed
?>
<html>
//some html
</html>
<?php
    header("Location: index.php") //This will fail
?>

//一些html
试试这个

      if (isset($sql_insert_contact)) {
         header("Location: index.php");
       }

试试这个

      if (isset($sql_insert_contact)) {
         header("Location: index.php");
       }

尝试添加ob_start();右键单击顶部第一个打开的php标记下方的行。在您的情况下,尝试将顶部更改为:

<?php
ob_start();
require_once "connection.php";
?>

您还应该考虑添加ob_end_flush();在文件的最底部

尝试添加ob_start();右键单击顶部第一个打开的php标记下方的行。在您的情况下,尝试将顶部更改为:

<?php
ob_start();
require_once "connection.php";
?>


您还应该考虑添加ob_end_flush();在文件的最底部

它是否保存为
.php
文件?是的,它保存为php文件sirSo,有什么错误?你能用错误信息编辑你的问题吗?只在第110行说错误。这就是为什么将
保存为
.php
文件的原因?是的,将其保存为php文件sirSo,错误是什么?你能用错误信息编辑你的问题吗?只在第110行说错误。这就是为什么你的
也可以使用输出缓冲,也可以使用输出缓冲,这就解决了它!谢谢你,修好了!非常感谢。