0

Hey guys, I'm trying to start a yes/no vote div which, when clicked, increments MySQL entry either way. I've seen several examples of how to do this type of thing online, but can't seem to grasp this process on my current layout. I'll show a little as possible to not overload you.

js

function vote(vote, item)
{
    $("#ajaxDiv").eq(0).load("pole.php?choice="+vote+"&item=" + item);
}

pole.php

<?php
    $con1 = mysql_connect(xxxx) or die(mysql_error());
    mysql_select_db(xxxx, $con1) or die(mysql_error());

    $item = stripslashes($_GET['item']);

    if ($_GET['choice']=="yes")
    {
        $update_query="UPDATE table SET yes = yes + 1 WHERE id='$item'";
        mysql_query($update_query, $con1);
    }
    else if ($_GET['choice']=="no")
    {
        $update_query="UPDATE table SET no = no + 1 WHERE id='$item'";
        mysql_query($update_query, $con1);
    }   

    $result = mysql_query("SELECT * FROM table ORDER BY id DESC");
    $row = mysql_fetch_array($result);
    ?>
    <p><? echo $row['question'] ?></p>
    <p><img src='img/layout/vote.jpg' width='250' height='71' alt='Vote Now!' usemap='#voteMap' /></p>";
    <map name="voteMap">
        <area shape="rect" coords="19,9,114,40" href="#" onclick="vote('yes', <? echo $row['id'] ?>)" alt="Yes">
        <area shape="rect" coords="133,9,229,40" href="#" onclick="vote('no', <? echo $row['id'] ?>)" alt="No">
    </map>

HTML

<div id="ajaxDiv">
    //similar code to pole.php minus php update calls
</div>

if I run it all together as is, it simply updates the "ajaxDiv" with the pole.php content not updated, however, If I run pole.php with the correct parameters (eg: pole.php?choice=yes&amp;item=3), it updates the database correctly.

EDIT: appears I was wrong on the PHP update, checking into that now

Edited by PsychicTide

1
Contributor
1
Reply
20
Views
3 Years
Discussion Span
Last Post by PsychicTide
0

Simple overlook as always, Sorry for the garbage post. Looks like I should have used an & symbol instead of &amp; in the js. Maybe this can help someone else with the basic idea.

Edited by PsychicTide

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.