私は、ユーザーがスライダーで選択した気分を投稿できるようにする関数をコーディングしようとしました。私はIDとの色を接続するのに成功し、私はポスト機能を作ってみました。しかし、何も起こらない。私の関数はデータベースに投稿しません
ここで私は関数を呼び出します。
if (isset($_POST['ready'])) {
$mood = new Post();
$moodColor = $_POST['mood'];
$statementMood = $mood->getMood($moodColor); //connects the color with an ID
while ($row = $statementMood->fetch(PDO::FETCH_ASSOC)) {
$moodID = $row['moodID'];
}
$moodID = $_GET['moodID'];
$userID = $currentUser['userID'];
$statementPost = $mood->postMood(); //put the emotion in the database.
//header('location: home.php');
}
これらは2つの機能です。
public function getMood($moodColor){
$conn = db::getInstance();
$statementMood = $conn->prepare("SELECT * FROM moods WHERE color = :cMood");
$statementMood->bindParam(":cMood", $moodColor);
$statementMood->execute();
return $statementMood;
}
public function postMood(){
$conn = db::getInstance();
$statementPost = $conn->prepare("INSERT INTO postsmoodi (userID, moodID) VALUES (:userID, :moodID)");
$statementPost ->bindValue(':userID', $this->userID);
$statementPost->bindValue(':moodID', $this->moodID);
return $statementPost->execute();
}
これは投稿するボタンのフォームです。
<form class="input" action="mood.php" method="get">
<input id="hiddenValue" type="hidden" class="data" name="mood" value="">
<button class="moodReady" type="submit" name="ready">Ready</button>
</form>
代わりにあなたのボタンがいくつかで提出され – DamiToma
ボタンは 'type'が' submit'を、フォームはgetを、OPは '$ _POST'を使ってデータにアクセスしています。 – julekgwa