php中出现意外的文件结尾?
我正在为一个项目编写这个php表单,出于某种原因,我在代码末尾收到了一条错误消息?谁能给我解释一下为什么会这样?这对未来的情况真的很有帮助php中出现意外的文件结尾?,php,mysql,Php,Mysql,我正在为一个项目编写这个php表单,出于某种原因,我在代码末尾收到了一条错误消息?谁能给我解释一下为什么会这样?这对未来的情况真的很有帮助 <?php require_once'login.php'; $conn=new mysqli($hn,$un,$pw,$db); if($conn->connect_error) die($conn->connect_error); if (isset($_POST['delete']) &
<?php
require_once'login.php';
$conn=new mysqli($hn,$un,$pw,$db);
if($conn->connect_error) die($conn->connect_error);
if (isset($_POST['delete']) && isset($_POST['isbn']))
{
$isbn = get_post($conn, 'isbn');
$query = "DELETE FROM publications WHERE isbn='isbn'";
$result = $conn->query($query);
if(!$result) echo "DELETE failed: $query </br>".
$conn->error."</br></br>";
}
if (isset($_POST['author']) &&
isset($_POST['title']) &&
isset($_POST['type']) &&
isset($_POST['year']) &&
isset($_POST['isbn']))
{
$author = get_post($conn, 'author');
$title = get_post($conn, 'title');
$type = get_post($conn, 'type');
$year = get_post($conn, 'year');
$isbn = get_post($conn, 'isbn');
$query = "INSERT INTO publications VALUES".
"( '$author', '$title', '$type', '$year' ,'$isbn')";
$result = $conn->query($result);
if(!$result) echo "INSERT failed :$query</br>".
$conn->error . "</br></br>";
}
echo <<<END
<form action = "sqltest.php" method="post"><pre>
Author <input type="text" name = "author">
Title <input type="text" name = "title">
Type <input type="text" name="Type">
Year <input type="text" name="year">
ISBN <input type="text" name="isbn">
<input type="submit" value="ADD RECORD">
</pre></form>
_END;
$query = "SELECT * FROM publications" ;
$result = $conn-query($query);
if(!$result) die("Database access failed:".$conn->error);
$rows = $result->num_rows;
for($j = 0; $j < $rows; ++$j)
{
$result->data_seek($j);
$row = $result->fetch_array(MYSQLI_NUM);
echo <<<_END
<pre>
Author $row[0]
Title $row[1]
Type $row[2]
Year $row[3]
ISBN $row[4]
</pre>
<form action ="sqltest.php" method="post">
<input type="hidden" name="delete" value="yes">
<input type="hidden" name ="isbn" value="$row[4]">
<input type="submit" value="DELETE RECORD"></form>
_END;
}
$result->close();
$conn->close();
function get_post($conn, $var)
{
return $conn->real_escape_string($_POST[$var]);
}
?>
注意:
- 您忘记在您的一个代码中添加下划线(
。
)
- 您忘记了插入查询的列
- 您在
$result=$conn query($query)中忘记了
代码>,应该是$result=$conn->query($query)代码>
代码:
Heredocs对它们的结束时间非常严格,所以它不会意外地结束在您不希望它结束的地方,它必须以开头字符结尾,前面绝对没有任何内容(没有空格,只有一行新行),后面是分号
因此:
echo在哪一行?那一行的代码是什么呢?Herdoc问题,我让你查一下:谢谢,记住这一点很有帮助
echo <<<_END
<form action = "sqltest.php" method="post"><pre>
Author <input type="text" name = "author">
Title <input type="text" name = "title">
Type <input type="text" name="Type">
Year <input type="text" name="year">
ISBN <input type="text" name="isbn">
<input type="submit" value="ADD RECORD">
</pre></form>
_END;
$query = "INSERT INTO publications VALUES (column1, column2, column3, column4)".
"('$author', '$title', '$type', '$year' ,'$isbn')";
echo <<< END
Some words and stuff
END; //Whitespace before END;
echo <<< END
Some words and stuff
END; //No whitespace before END;