语法错误,运行php7的文件意外结束

kt06eoxx  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(282)

在过去的一个小时里,我似乎不明白我的代码出了什么问题,我是新的编码,我做了一些研究,打开了短标签,但我似乎仍然得到一个意想不到的文件结束错误。任何帮助都是惊人的

<?php

include("config.php");

if($submit)
{//begin of if($submit).

// Set global variables to easier names
$title = $_POST['title'];
$text1 = $_POST['text1'];
$text2 = $_POST['text2'];

//check if (title) field is empty then print error message.
if(!$title){ //this means If the title is really empty.
echo "Error: News title is a required field. Please fill it.";
exit(); //exit the script and dont do anything else.
}// end of if
//run the query which adds the data gathered from the form into the database
$result = mysqli_query("INSERT INTO news (title, dtime, text1, text2)
VALUES ('$title',NOW(),'$text1','$text2')",$connect);
//print success message.
echo "<b>Thank you! News added Successfully!<br>You'll be redirected to Home Page after (4) Seconds";
echo "<meta http-equiv=Refresh content=4;url=index.php>";
}//end of if($submit).

// If the form has not been submitted, display it!
else
{//begin of else

?>
<br>
<h3>::Add News</h3>

<form method="post" action="<?php echo $PHP_SELF ?>">
Title: <input name="title" size="40" maxlength="255">
<br>
Text1: <textarea name="text1" rows="7" cols="30"></textarea>
<br>
Text2: <textarea name="text2" rows="7" cols="30"></textarea>
<br>
<input type="submit" name="submit" value="Add News">
</form>
<?
}//end of else

?>
wwtsj6pe

wwtsj6pe1#

<?php
    include("config.php");
    $error=0;
    if(isset($_POST['submit']))
    {
    // Set global variables to easier names
    $title = $_POST['title'];
    $text1 = $_POST['text1'];
    $text2 = $_POST['text2'];
    //check if (title) field is empty then print error message.
    if(empty($title))
     { //this means If the title is really empty.
    echo "Error: News title is a required field. Please fill it.";
    $error=1;
    }
    }
    ?>
<html><body>
    <br>
    <h3>::Add News</h3>

    <form method="post" action="<?php echo $PHP_SELF ?>">
    Title: <input name="title" size="40" maxlength="255">
    <br>
    Text1: <textarea name="text1" rows="7" cols="30"></textarea>
    <br>
    Text2: <textarea name="text2" rows="7" cols="30"></textarea>
    <br>
    <input type="submit" name="submit" value="Add News">
    </form>
</body></html>
    <?php
    if(isset($_POST['submit']) && $error==0)
{
//run the query which adds the data gathered from the form into the database
    $sql = "INSERT INTO news (title, dtime, text1, text2)
    VALUES ('$title',NOW(),'$text1','$text2')"
    $result=$conn->query($sql);
    if ($result==="TRUE")
    echo "<b>Thank you! News added Successfully!<br>You'll be redirected to Home Page after (4) Seconds";
    echo "<meta http-equiv=Refresh content=4;url=index.php>";
}
    ?>

希望这能回答你的问题。如果有,请给我的答案打分。

相关问题