druybew06513 2018-04-01 16:02
浏览 30

从表格发送信息的问题

EDIT: Solved the issue. In the php code $q and $q2 did not get query.

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

I'm trying to make a micro blog new feed for a class that I'm in and I am having difficulty sending information from a post to update the like and dislike buttons. Below is the code for the post;

<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>

Also here is the php code;

<?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();
}
?>

As of now I think the issue is there is nothing being sent in the POST variable because if I put an echo after the first if nothing appears to happen. Where I'm trying to send postID so that I can update the likes and dislikes on the server.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?