我正在尝试编写 php 代码,但在使用 post 数组时遇到了一些问题。我尝试访问该数组以便可以放入 MySQL,但无论我尝试什么,该数组总是以空结束。这是我的代码的副本。任何帮助是极大的赞赏。
<?php
//$comment=$_POST['Comment'];
require login.php; //Defines $host, $username, $password and $database with login credentials
$con=mysqli_connect($host, $username, $password, $database);
if(mysqli_connect_errno())
echo "Failed to connect to MySQL: ".mysqli_connect_error();
if(isset($_POST[Comment]))
{
$comment=getPost('Comment');
echo "The comment is: $_POST[0]";
}
$date= getDate();
if(!mysqli_query($con, "INSERT INTO Comments(Date, Type, User, Comment)
VALUES ('$date[month]-$date[mday]-$date[year]', 0,'Jimmy Barrientos', '$comment')"))
{
echo"INSERT failed: <br/>".mysql_error()."<br/><br/>";
}
echo <<<_END
<form action="addComment.php" method="get"><pre>
Comment<br/>
<textarea rows="5" cols="50" name="Comment">
Type in comment here
</textarea>
<input type="submit" value="Add Comment"/>
</pre></form>
_END;
function getPost($var)
{
return mysql_real_escape_string($_POST[$var]);
}
?>