我是PHP的新手,但是我需要帮助,我想在发表评论的过程中从其数据库中获取用户名和图像,并将其插入要发表评论的登录用户中。
这是我的代码
<?php
include('dbconnect.php');
$error = '';
$username = '';
$post = '';
$username = $_POST["username"];
$user_image = $_POST["user_image"];
$post = $_POST["post"];
$time = $_POST["time"];
if(empty($_POST["post"]))
{
$error .= '<p class="text-danger">Empty post!</p>';
}
else
{
$post = $_POST["post"];
}
if($error == '')
{
$query = "
INSERT INTO comments
(comment_id, username, user_image, post, time)
VALUES (:comment_id, :username, :user_image, :post, :time)";
$statement = $con->prepare($query);
$statement->execute(
array(
':comment_id' => '0',
':post' => $post,
':username' => $username
':user_image' => $user_image,
':post' => $post,
'time' = $time
)
);
$error = '<label class="text-success">Comment Added</label>';
}
$data= array(
'error' => $error
);
echo json_encode($data);
?>