开发者

Like/Dislike system like FB

开发者 https://www.devze.com 2023-03-20 16:21 出处:网络
I have my tables set and the design I wanted...the only thing in my way of creating a sexy like/dislike system for my site is the actual PHP it would take (dont worry i wrote a bunmch of the code, its

I have my tables set and the design I wanted...the only thing in my way of creating a sexy like/dislike system for my site is the actual PHP it would take (dont worry i wrote a bunmch of the code, its just not sending)

My problem is that my code isnt sending to any of the tables, so my question to you is how would I a开发者_如何学Cctually get it to send to the db?

Here's the code I have in place so far (along with the button)

Button

<form action="up.php">
<input type="image" value="upBtn" name="upBtn" id="upBtn" src="images/add.png"> Like
</form>

Actual code (up.php)

  <?php
    require 'connect2.php';

    if (isset($_POST['upBtn'])) {
               mysql_query("INSERT INTO votes (id, user, upvote, downvote) VALUES ('', '$username', '+ 1', '+ 0')");
               mysql_query("UPDATE searchengine SET rel = rel '+ 1' WHERE id = '$id'");
            }
    ?>

$user name def (on the top of the page all of this code is on)

if (isset($_SESSION['id'])) {
    $userid = $_SESSION['id'];
    $username = $_SESSION['username'];

$id was already defined on the page since all of this is on the page I wanted the votes to appear


You should include the "id" as a hidden field in the form, as the id in the session may not be the id they are voting one, for instance, if they opened another post in a separate tab, and then voted on one that had been loaded before. Also, are you sure the session variables are being saved correctly? Depending on your PHP configuration, sessions are not started by default, in order to conserve resources, and you have to call session_start() at the top of each page to actually start the session.


Try adding method="post" to the form tag. If it still doesn't work, you should put some debugging code inside the if statement to see if your queries are actually being run.

0

精彩评论

暂无评论...
验证码 换一张
取 消