0

私はphpコードを試していますが、投稿配列の使用に問題があります。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]);
}
?>
4

2 に答える 2