从表格发送信息的问题

时间:2018-04-01 16:02:32

标签: php mysql database forms

编辑:解决了这个问题。在PHP代码中,$ q和$ q2没有得到查询。

$r1 = $db->query($q);
$r2 = $db->query($q2);

我正在尝试为我所在的课程制作一个微博客新的Feed,但我很难从帖子中发送信息来更新喜欢和不喜欢的按钮。以下是帖子的代码;

<form action="Assignment4_Main.php" method="post">
    <div class="newsFeed">
        <input type="hidden" name="submitted" value="1"/>
        <a href="Assignment4_Profile.php"><?php echo $username?>
        </a>
        <input class="idr" name="postID" type="text" value=<?php echo $postID ?> />
        <p>
        <?php echo $text?>
        </p>
        <p>
        Posted: <?php echo $pTime?>
        </p>
        <input type="image" name="liked" src="Like_Not.png" alt="submit" width="20" height="20" value="1"/>
        <p>
        Likes: <?php echo $likes?>
        </p>
        <input type="image" name="disliked" src="Dislike_Not.png" alt="Dislike" width="20" height="20" value="1"/>
        <p>
            Dislikes: <?php echo $dislikes?>
        </p>
        <input type="image" name="reposted"  src="Repost_Not.png" alt="Repost"         width="20" height="20" value="1"/>
        </br>
    </div>
</form>

这里还有php代码;

<?php 
    if(isset($_POST["postID"])){
    $idPost = ($_POST["postID"]);

    $db = new mysqli("host", "username", "password", "username");
    if ($db->connect_error) {
        die ("Connection failed: " . $db->connect_error);
    }

    $gettingUser = "SELECT * FROM Post WHERE post_id = '$idPost';";
    $r = $db->query($gettingUser);
    $row = $r->fetch_assoc();
    $gotID = $row["user_id"];

    $r = $db->query($gettingUser);
    $row = $r->fetch_assoc();
    $gotLikes = $row["likes"];
    $gotLikes++;

    $q = "insert into Likes (user_that_like_id, post_id) values ('$gotID', '$idPost');";
    $q2 = "update Post set likes='$gotLikes' where post_id='$idPost';";
    header("Location: Assignment4_Main.php");
    $db->close();
    exit();
}
?>

截至目前,我认为问题是POST变量中没有发送任何内容,因为如果我在第一个之后放置一个回声,如果没有发生任何事情。我试图发送postID以便我可以更新服务器上的喜欢。

0 个答案:

没有答案