Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP HTML Heredoc解析错误:语法错误,意外'&引用';_Php_Html - Fatal编程技术网

PHP HTML Heredoc解析错误:语法错误,意外'&引用';

PHP HTML Heredoc解析错误:语法错误,意外'&引用';,php,html,Php,Html,因此,我在PHP块中为表单编写HTML代码,如下所示: 在PostgreSQL数据库中添加新记录 .错误{color:#FF0000;} $con=pg\u connect(“主机=$host端口=$port dbname=$db用户=$user密码=$pass”) 或死亡(“无法连接到服务器\n”); 如果(空($_POST['title'])) { $titleErr=“需要标题”; displayForm(); } 其他的 { processForm(); } } 其他的 { displa

因此,我在PHP块中为表单编写HTML代码,如下所示: 在PostgreSQL数据库中添加新记录 .错误{color:#FF0000;}
$con=pg\u connect(“主机=$host端口=$port dbname=$db用户=$user密码=$pass”)
或死亡(“无法连接到服务器\n”);
如果(空($_POST['title']))
{
$titleErr=“需要标题”;
displayForm();
}
其他的
{
processForm();
}
}
其他的
{
displayForm();
}
函数processForm(){
$title=$_POST['title'];
$author=$_POST['author'];
$status=$_POST['status'];
$remark=$_POST['remark'];
$story=$_POST['story'];
$art=$_POST['art'];
如果($story=='')
{
$story=0;
}
如果($art='')
{
$art=0;
}
$query=“插入评级”。
“(标题、作者、故事、艺术、地位、评论)”。
“值(“$title”、“$author”、$story、$art、$status”、“$remark”)”;
$rs=pg_query($con,$query)或die(“无法执行查询:$query,因为“.pg_last_error()。”\n”);
/************************************************
将上载的图像保存到服务器中
************************************************/
echo“已成功输入数据\n”;
pg_关闭($con);
}
函数displayForm()
{
在
PHP\u SELF
关闭初始代码之前,打印“

你应该写:


您应该像这样将索引变量封装在带引号的字符串或herdoc中:
{$\u SERVER[“PHP\u SELF”]}


但这并不是你唯一的问题。你的下一个问题是你试图用herdoc语法打开一个你不能使用的


您还应该查看

请删除代码中不需要的部分,并仅显示引发错误的行(可能是某些上下文,但不是所有代码)。您的解决方案是否显示了此错误。它给出了以下错误:解析错误:语法错误,意外的“”(T_封装的_和_空格),需要标识符(T_字符串)或变量(T_变量)或数字(T_NUM_STRING)您刚刚取出
htmlspecialchars()
?这可能就是OP甚至试图打开
的全部原因。我只是错过了它。我刚刚更正了代码OK,它确实解决了问题。但是,我在提交时被禁止访问。URL现在在action@DawinWidjaja我不明白你的意思,你说的是什么?”URL现在在action“”中附加了字符串?别介意,这是在您修改解决方案之前。我现在理解了,并且它已经在参数中进行了一些调整。问题是在php中添加了字符串。
$con= pg_connect("host=$host port= $port dbname=$db user=$user password=$pass") 
    or die ("Could not connect to server\n");
if(empty($_POST['title']))
{
    $titleErr= "Title is required";
    displayForm();
}
else
{
    processForm();

}
}

else
{
displayForm();
}

function processForm(){
$title = $_POST['title'];
$author = $_POST['author'];
$status = $_POST['status'];
$remark = $_POST['remark'];
$story = $_POST['story'];
$art = $_POST['art'];
if($story=='')
{
$story=0;
}
if($art=='')
{
$art=0;
}

$query = "INSERT INTO rating ".
   "(title,author,story,art, status, remarks) ".
   "VALUES('$title','$author',$story, $art,'$status','$remark')";
$rs= pg_query($con, $query) or die ("Cannot execute query:$query because".pg_last_error()."\n");

/************************************************
Save uploaded image in server
************************************************/
echo "Entered data successfully\n";
pg_close($con);
}

function displayForm()
{
print<<<END
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" enctype="multipart/form-data">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Title</td>
<td><input name="title" type="text" id="title"><span class="error">* <?php echo $titleErr;?></span></td>
</tr>
<tr>
<td width="100">Author</td>
<td><input name="author" type="text" id="author"></td>
</tr>
<tr>
<td width="100">Story Rating</td>
<td><input name="story" type="text" id="story"></td>
</tr>
<tr>
<td width="100">Art Rating</td>
<td><input name="art" type="text" id="art"></td>
</tr>
<tr>
<td width="100">Remarks</td>
<td><input name="remark" type="text" id="remark"></td>
</tr>
<tr>
<td width="100">Status</td>
<td><input name="status" type="text" id="status"></td>
</tr>
<tr>
<td width="100">Image</td>
<td><input name="file" type="file" id="file"></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="add" type="submit" id="add" value="Add Entry">
</td>
</tr>
</table>
</form>
END;
}
?>
</body>
</html>
print<<<END
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" enctype="multipart/form-data">
$phpself = htmlspecialchars($_SERVER["PHP_SELF"]);
print<<<END
<form method="post" action="$phpself" enctype="multipart/form-data">
<td><input name="title" type="text" id="title"><span class="error">* <?php echo $titleErr;?></span></td>
<td><input name="title" type="text" id="title"><span class="error">* $titleErr</span></td>
function displayForm()
{
$htmlspecialchars = 'htmlspecialchars';
print <<<END
<form method="post" action="{$htmlspecialchars($_SERVER["PHP_SELF"])}" enctype="multipart/form-data">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Title</td>
<td><input name="title" type="text" id="title"><span class="error">* {$titleErr}</span></td>
</tr>
<tr>
<td width="100">Author</td>
<td><input name="author" type="text" id="author"></td>
</tr>
<tr>
<td width="100">Story Rating</td>
<td><input name="story" type="text" id="story"></td>
</tr>
<tr>
<td width="100">Art Rating</td>
<td><input name="art" type="text" id="art"></td>
</tr>
<tr>
<td width="100">Remarks</td>
<td><input name="remark" type="text" id="remark"></td>
</tr>
<tr>
<td width="100">Status</td>
<td><input name="status" type="text" id="status"></td>
</tr>
<tr>
<td width="100">Image</td>
<td><input name="file" type="file" id="file"></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="add" type="submit" id="add" value="Add Entry">
</td>
</tr>
</table>
</form>
END;
}
?>