Some help needed

Discussion in 'PHP' started by cipcip, Mar 24, 2011.

  1. #1
    Ok, so I am creating a like system like the one on youtube. I have a problem, the code is not working, I do not know what I am doing wrong since I don't get any errors and I am stuck like this for 2 days now.

    
    <?php
    echo "<a href='{$_SERVER['PHP_SELF']}?vot=up&idpost=$idpost'";
    ?>
    onclick="return confirm('Multumim pentru votul pozitiv!')"
    <?php
    echo'><img src="images/up.png" alt="Vote UP" /></a>';
    ?> <?php
    echo "<a href='{$_SERVER['PHP_SELF']}?vot=down&idpost=$idpost'";
    ?>
    onclick="return confirm('Ne pare rau ca nu ti-a placut acest post!')"
    <?php
    echo'><img src="images/down.png" alt="Vote DOWN" /></a>';
    
    if(!isset($_GET['vot'])) $_GET['vot'] = '';
    
    switch($_GET['vot'])
    {
    case '':
    echo '';
    break;
    
    case 'up':
    
    $query12="SELECT idlike, up, down, idpost FROM like INNER JOIN posts ON like.idpost=posts.idpost WHERE idpost=$idpost";
    $result12 = mysql_query($query12);
    if ($row=mysql_fetch_assoc($result12))
    {
    //UPDATE
    $increment = $row['up']+1;
    $query13 = "UPDATE like SET up=$increment WHERE idpost=$idpost";
    $result13 = mysql_query($query13);
    }
    else
    {
    //INSERT
    $implicit=1;
    $query21 = "INSERT INTO like (idlike, idpost, up) VALUES ('', '$idpost', '$implicit')";
    $result21 = mysql_query($query21);
    }
    
    break;
    
    case 'down':
    
    $query14="SELECT idlike, up, down, idpost FROM like INNER JOIN posts ON like.idpost=posts.idpost WHERE idpost=$idpost";
    $result14 = mysql_query($query14);
    if ($row=mysql_fetch_assoc($result14))
    {
    //UPDATE
    $increment2 = $row['down']+1;
    $query15 = "UPDATE like SET down=$increment2 WHERE idpost=$idpost";
    $result15 = mysql_query($query15);
    }
    else
    {
    //INSERT
    $implicit2=1;
    $query22 = "INSERT INTO like (idlike, idpost, down) VALUES ('', '$idpost', '$implicit2')";
    $result22 = mysql_query($query22);
    }
    
    break;
    }
    ?>
    
    PHP:
    Thanks in advance!
     
    cipcip, Mar 24, 2011 IP
  2. bledileka

    bledileka Peon

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i have developed somthing like this but im not sharing the script :). Instead u can use it for free :
    http://www.votemyweb.com/
    Code (markup):
     
    bledileka, Mar 24, 2011 IP
  3. cipcip

    cipcip Well-Known Member

    Messages:
    1,935
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    160
    #3
    Thanks but I can't use it because it is for my end of the university degree project. :)
     
    cipcip, Mar 24, 2011 IP