我想向朋友发送消息,但它不想进入我的数据库,但即使我使用 $_POST,它也会显示在 url 中。我得到了我的 currentuserID 和我的 recipientID(我需要发送给的人)因为我 var_dump 了这两个并且得到了两个 ID。我的 SQL 查询应该没有错我以为我已经与多个人核实过(但是当我在数据库中测试时它给出了一个错误。但是当我在其中放入另一个有效的查询时,它给出了同样的错误所以我不'不认为这是一个问题)。
所以我不知道这里可能是什么问题..
我的消息.php:
<?php
session_start();
if (empty($_SESSION['user_id'])) {
header('Location: login.php');
}
//Hier mag enkel het gesprek te zien zijn tussen 2 users die met elkaar bevriend zijn
//tabel buddies >buddyID1 & buddyID2
include_once(__DIR__."/inc/header.inc.php");
include_once(__DIR__."/classes/Message.php");
include_once(__DIR__."/classes/User.php");
$userArray = $_SESSION['user_id'];
$userID = implode(" ", $userArray);
$currentUser = $userID;
//var_dump($_POST);
$recipientID = implode(" ",$_POST);//om het getal terug te krijgen van de recipientID
echo "currentUser: ";
var_dump($currentUser);
echo ". recipientID: ";
var_dump($recipientID);
//msg wordt in databank gestopt
if(!empty($_POST['message'])){
$msg = new Message();
$msg->setUserID($currentUser);
$msg->setRecipientID($recipientID);
$msg->setMessage(htmlspecialchars($_POST['message']));
$msg->messageSchrijven();
}
//msg wordt afgedrukt/gereturned
$msg2 = new Message();
$messages = $msg2->messagePrint();
?><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>
<form action="" methd="post">
<h1>Je chat nu met <?php echo $recipientID ?></h1>
<input type="text" name="message">
<input type="hidden" name="recipientID" id="" value="<?php echo $recipientID?>">
<input type="hidden" name="senderID" id="" value="<?php echo $currentUser?>">
<div class="">
<button type="submit" class="btn" style="width: 90px">Send</button>
</div>
</form>
</div>
</body>
</html>
catspeake