gpt4 book ai didi

php - PHP 文件意外结束?

转载 作者:可可西里 更新时间:2023-11-01 08:45:14 25 4
gpt4 key购买 nike

我正在为一个项目编写此 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']) && 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]);
}
?>

最佳答案

备注:

  • 您忘记了您的 heredoc 之一的下划线 ( _ )。
  • 您忘记了插入查询的列。
  • 你忘记了>在你的 $result = $conn-query($query); ,应该是$result = $conn->query($query);

代码:

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')";

关于php - PHP 文件意外结束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30858410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com