I am a no good in PHP (just learning).
I tried modifying a php voting script which I downloaded from a free source. i can add image though (it was not an easy task for me and I am not done yet).
Now Voting works fine on my local server , but online it doesn't. If I click to vote, the numbers just disappear without return. below are the codes to look into.
index.php ---
<?php include('config.php');
$sql=mysql_query("SELECT * FROM messages ORDER BY `messages`.`up` DESC LIMIT 20");
while($row=mysql_fetch_array($sql)) { $title=$row['title']; $desc=$row['desc'];
$mes_id=$row['mes_id']; $image=$row['image']; $up=$row['up'];
$down=$row['down']; ?> <div id="vote"> <div class="box1">
<div class='up'><a href="" class="vote" id="<?php echo $mes_id; ?>" name="up">
<?php echo $up; ?></a></div>
<div class='down'><a href="" class="vote" id="<?php echo $mes_id; ?>" name="down">
<?php echo $down; ?></a></div></div>
<div class='image' ><?php echo "<img src=user/admin/".$image ." width='87%' height='70%'/>"?></div>
<div class ='title'><?php echo $title; ?></div>
<div class='box2' >
<?php echo $desc; ?> </div> </div>
<?php } ?>
up_vote.php --------------------------
<?php include("config.php");
$ip=$_SERVER['REMOTE_ADDR'];
if($_POST['id']) { $id=$_POST['id']; $id = mysql_real_escape_String($id); $ip_sql=mysql_query("SELECT ip_add FROM voting_ip WHERE mes_id_fk='$id' AND ip_add='$ip'");
$count=mysql_num_rows($ip_sql)or die(mysql_error());
if($count<=20)
{
$sql = "UPDATE messages SET up=up+1 WHERE mes_id='$id'"; mysql_query( $up);
$sql_in = "INSERT INTO messages (mes_id_fk,ip_add) VALUES ('$id','$ip')"; mysql_query( $sql_in);
} else
{ echo "<script>alert('You have already voted');</script>"; }
$result=mysql_query("SELECT up FROM messages WHERE mes_id='$id'");
$row=mysql_fetch_array($result); $up_value=$row['up']; echo $up_value; } ?>
down_vote.php -----------------------------
<?php include("config.php");
$ip=$_SERVER['REMOTE_ADDR'];
if($_POST['id']) { $id=$_POST['id'];
$id = mysql_real_escape_String($id);
$ip_sql=mysql_query("SELECT ip_add FROM voting_ip WHERE mes_id_fk='$id' AND ip_add='$ip'");
$count=mysql_num_rows($ip_sql) or die(mysql_error());
if($count<=0)
{ $sql = "UPDATE Messages SET down=down+1 WHERE mes_id='$id'"; mysql_query( $sql);
$sql_in = "INSERT INTO voting_ip (mes_id_fk,ip_add) values ('$id','$ip')"; mysql_query( $sql_in);
} else { echo "<script>alert('You have already voted');</script>"; }
$result=mysql_query("SELECT down FROM Messages WHERE mes_id='$id'");
$row=mysql_fetch_array($result);
$down_value=$row['down']; echo $down_value; }
?>
Javascript --------------------------- (this is at the index header with some HTML codes)
<script type="text/javascript">
$(function() {
$(".vote").click(function()
{
var id = $(this).attr("id");
var name = $(this).attr("name");
var dataString = 'id='+ id ;
var parent = $(this);
if(name=='up')
{
$(this).fadeIn(200).html('<img src="dot.gif" align="absmiddle">');
$.ajax({
type: "POST",
url: "up_vote.php",
data: dataString,
cache: false,
success: function(html)
{
parent.html(html);
} });
}
else
{
$(this).fadeIn(200).html('<img src="dot.gif" align="absmiddle">');
$.ajax({
type: "POST",
url: "down_vote.php",
data: dataString,
cache: false,
success: function(html)
{
parent.html(html);
}
});
}
return false;
});
});
</script>
I appreciate anyone helping out, thanks everyone.
From your code,
if($count==50)
then only the values are being updated!!. How is it possible for a person who is going to vote for the first time???
It should be
if($count<50)
Going to take a wild stab here but 9/10 'It works locally but not on live' issues are either php version mismatches or differences in Apache config (differing module configurations etc) presuming LAMP.
Check the php versions match and if they don't check the change logs to detect any functions that do not work within both. This is likely the issue.
And as commented above. Always check your server logs.
Related
First let me show you the code
This is the script
var user_id = $(this).attr("id");
var datastring = 'user_two='+ user_id;
$(".follow").click(function(){
$.ajax({
type: "POST",
url: "include.php",
data: datastring,
success: function(html){}
});
$("#follow"+user_id).hide();
$("#unfollow"+user_id).show();
return false;
});
Here is php
<?php
$query = $handler->query("SELECT * FROM users");
while ($row = $query->fetch()) {
$user_two = $row['id'];
$user_one = 1;
?>
<p><?php echo $row['username'];?></p>
<?php
$follow_check = $handler->query("SELECT * FROM follow WHERE user_one='$user_one' AND user_two='$user_two'");
if ($follow_check->rowCount() == 0) {?>
<div id="follow<?php echo $user_one;?>">
Follow
</div>
<div id="unfollow<?php echo $user_one;?>" style='display:none'>
Following
</div>
<?php }else{?>
<div id="follow<?php echo $user_one;?>" style='display:none'>
Follow
</div>
<div id="unfollow<?php echo $user_one;?>" >
Following
</div>
<?php } ?>
<?php } ?>
Here is the php for Insert query
<?php
include('db.php');
$user_two = $_POST['user_two'];
$query = $handler->query("INSERT INTO follow (user_one,user_two) VALUES ('1','$user_two')");
?>
there two things i need to insert which is user_one = Session=0 or the current logged in user but i just made it static for the mean time and the user_two which is the users id or the one you will click to follow that person. But idk how to do it in ajax, like in php you can get the value of the link like <a href="?id="> and then to get the value, $_GET['id'] but idk how to store that value to script
I just need an explanation on user_id = $(this).attr("id");
and the return false inside the $(".follow").click and when I make it to false i need to refresh the page just to see the changes of links to follow and following why is it like that?
By the way, When i click the follow link it will successfuly insert to the database but the user_two's value is always 0 because I dont know how to store link id to the script.
Not 100% sure if i understood but let me try:
First: id="<?php echo $user_id; ?>" it's ok.
You can get it with var user_id = $(this).attr("id");
Maybe you should move this line inside the $(".follow")... block
$(".follow").click(function() {
var user_id = $(this).attr("id"); //"this" will refer the element with the "follow" class. Then user_id will be the value of the id for the clicked element.
$.ajax({
type: "POST",
url: "include.php",
data: {user_two: user_id}
}).done(function(data) {
data = JSON.parse(data);
if(data.msg) {
//everything is ok
$("#follow"+user_id).hide();
$("#unfollow"+user_id).show();
} else {
//handle the error
}
)}
});
PHP part:
<?php
include('db.php');
$user_two = $_POST['user_two'];
$query = $handler->query("INSERT INTO follow (user_one,user_two) VALUES ('1','$user_two')");
if($query) { //check if query ran successfully
echo json_encode(array("msg" => 1)); 1 for success
} else {
echo json_encode(array("msg" => 2)); 2 for error
}
?>
As for the "what is return false in ajax":
.follow -> targets an tag. Clicking on an a tag makes your browser navigate to the url specified in href="". return false disables this behaviour as you don't need the page to refresh or go to another page :)
I am trying to post a variable clicked by an user to a PHP script in order to run a query which will further extract information from the database. I am able to get the value that has been clicked by an user without any issue. However I believe it is not getting processed within the query hence why when I run it in Firebug it shows an empty response and HTML.
I think I need some changes with my test.php script or may be ajax part of index.php
Index.php
<?php
$test = $_GET['product'];
$q = "SELECT * FROM prdct_categories WHERE product = '$test' ";
$r = mysqli_query($dbc, $q);
$path_info = get_path();
$test1 = $path_info['call_parts'][1];
while ($list = mysqli_fetch_assoc($r)) { ?>
<li class="nav" <?php if ($test1 == $list['slugs']) { echo'id="actives"'; } ?>>
<a href="<?php echo $test;?>/<?php echo $list['slugs'];?> ">
<?php echo $list['subgroup'] . "(" . $list['contains'] . ")" . '<br/>'; ?>
</a>
</li>
<?php } ?>
</div>
<div class="col-md-4" id="testing"></div>
<script>
$(document).ready(function() {
$(".nav > a").click(function(e){
e.preventDefault();
$.post("test.php", { value:$(this).text() }, function(data) {
$("#testing").html(data);
});
});
//var classprod = $(this).text();
//$("#testing").text(classprod);
});
</script>
test.php
<?php
require('../config/connection.php');
if (isset($_POST['value'])) {
$value = $_POST['value'];
$query = "SELECT * FROM prdct_categories WHERE class = '$value'";
$result = mysqli_query($dbc, $query);
while ($row = mysqli_fetch_assoc($result)) {
$prdct = print_r ($row['product']);
echo $prdct;
}
}
?>
remove "<br>" from
<a href="<?php echo $test;?>/<?php echo $list['slugs'];?> ">
<?php echo $list['subgroup']."(".$list['contains'].")".'<br/>';?></a>
and try
or try in js as
$.post("test.php", {value:(($(this).text()).trim())},
Change this:
$prdct = print_r ($row['product']);
To this:
$prdct = $row['product'];
Also change this:
$(".nav > a").click(function(e){
e.preventDefault();
$.post("test.php", {value:$(this).text()},
function(data) {$("#testing").html(data);});
});
To this:
$(".nav > a").click(function(e){
$.ajax({
type: "POST",
url: "test.php",
data: {value: $(this).text()},
success: function( msg ){$("#testing").html(msg);}
})
});
I am working on a voting system in jquery. I have it where a user can vote up or if they change their mind vote down and it deducts from the upvote and puts it in on the down vote. But my problem is I cant get both numbers to refresh when a vote is selected so it just uses the original number instead of the updated number.
Vote Page
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$(".vote").click(function() {
var id = $(this).attr("id");
var name = $(this).attr("name");
var dataString = 'id=' + id;
var parent = $(this);
if (name == 'up') {
$.ajax({
type: "POST",
url: "up_vote.php",
data: dataString,
cache: false,
success: function(html) {
parent.html(html);
}
});
} else {
$.ajax({
type: "POST",
url: "down_vote.php",
data: dataString,
cache: false,
success: function(html) {
parent.html(html);
}
});
}
return false;
});
});
</script>
<?php
$sql=mysql_query("SELECT * FROM uploads LIMIT 9");
while($row=mysql_fetch_array($sql))
{
$msg=$row['title'];
$mes_id=$row['id'];
$up=$row['up'];
$down=$row['down'];
?>
<a href="" class="vote" id="
<?php echo $mes_id; ?>" name="up">
<?php echo $up; ?> up
</a>
<div class='down'>
<a href="" class="vote" id="
<?php echo $mes_id; ?>" name="down">
<?php echo $down; ?>
</a>
</div>
<div class='box2' >
<?php echo $msg; ?>
</div>undefined</div>undefined
<?php } ?>
The up_vote.php page..
(down_vote.php is exactly the same as up_vote except it just changes up to down.)
<?php
include("config.php");
$ip = $_SERVER['REMOTE_ADDR'];
if ($_POST['id']) {
$id = $_POST['id'];
$id = mysql_escape_String($id);
//Verify IP address in Voting_IP table
$ip_sql = mysql_query("select ip from votes where img_id='$id' and ip='$ip'");
$count = mysql_num_rows($ip_sql);
if ($count == 0) {
// Update Vote.
$sql = "UPDATE uploads SET up=up+1 WHERE id='$id'";
mysql_query($sql);
// Insert IP address and Message Id in Voting_IP table.
$sql_in = "insert into votes (id,img_id,ip,type) values ('','$id','$ip','up')";
mysql_query($sql_in);
} else {
//if already voted change it..
$result = mysql_query("SELECT * FROM votes WHERE img_id='$id' AND ip='$ip'");
while ($row = mysql_fetch_array($result)) {
$vote_type = $row['type'];
}
if ($vote_type == 'down') {
$up = mysql_query("UPDATE uploads SET up=up+1 WHERE id='$id'");
$down = mysql_query("UPDATE uploads SET down=down-1 WHERE id='$id'");
$vote = mysql_query("UPDATE votes SET type=up WHERE img_id='$id' AND ip='$ip'");
}
}
$result = mysql_query("select up from uploads where id='$id'");
$row = mysql_fetch_array($result);
$up_value = $row['up'];
echo $up_value;
}
?>
Not an answer but too long for a comment. This script:
while ($row = mysql_fetch_array($result)) {
$vote_type = $row['type'];
}
if ($vote_type == 'down') {
/* ... */
}
I don't think you need it like it is now. You are actually only using the last fetched row, not all of them. If that's your intention (because there's only one), then you don't need the while() at all. You could change it for:
$row = mysql_fetch_row($result);
$vote_type = $row['type'];
if ($vote_type == 'down') {
/* ... */
}
Furthermore, I'd recommend to change your code to PDO. It's more secure and mysql_* is deprecated.
I need to load $message1 and $message2 back into index.php when the corresponding anchors are clicked, with ajax, so that the new values are displayed in index.php without the page resfreshing. this code functions as is, I just can't figure out how to do this, could anybody help me figure out how? I've never written this type of script before and have gotten a little advice on how to do it but I'm still very confused.
this is my general.js file
$(".vote").click(function() {
var id = $(this).attr("id");
var name = $(this).attr("name");
var eData = $(this).attr("data-options");
var dataString = 'id='+ id + '&' + eData ;
var parent = $(this);
if(name=='up')
{
$(this).fadeIn(200).html('');
$.ajax({
type: "POST",
url: "up.php",
data: dataString,
cache: false,
success: function(html){
parent.html(html);
}
});
}
else
{
$(this).fadeIn(200).html('');
$.ajax({
type: "POST",
url: "down.php",
data: dataString,
cache: false,
success: function(html){
parent.html(html);
}
});
}
});
here is the html from my index.php
<?php
$sql = mysql_query("SELECT * FROM blogData ORDER BY id DESC");
$sql2=mysql_query("SELECT * FROM messages WHERE mod(mes_id,2) = 0 ORDER BY mes_id DESC");
$sql3=mysql_query("SELECT * FROM messages WHERE mod(mes_id,2) = 1 ORDER BY mes_id DESC");
$count_variable = 0;
while(($row = mysql_fetch_array($sql))AND($row2 = mysql_fetch_array($sql2))AND($row3 = mysql_fetch_array($sql3)) ){
$id = $row['id'];
$title = $row['title'];
$content = $row['content'];
$category = $row['category'];
$podcast = $row['podcast'];
$datetime = $row['datetime'];
$message1=$row2['msg'];
$mes_id1=$row2['mes_id'];
$totalvotes1=$row2['totalvotes'];
$message2=$row3['msg'];
$mes_id2=$row3['mes_id'];
$totalvotes2=$row3['totalvotes'];
?>
<table class="content">
<tr>
<td>
<div id="main">
<div id="left">
<span class='up'><img src="up.png" alt="Down" /></span><br />
<?php echo $totalvotes1; ?><br />
</div>
<div id="message">
<?php echo $message1; ?>
</div>
<div class="clearfix"></div>
</div>
<div id="main">
<div id="right">
<br />
<?php echo $totalvotes2; ?><br />
<span class='down'><img src="down.png" alt="Down" /></span>
</div>
<div id="message">
<?php echo $message2; ?>
</div>
<div class="clearfix"></div>
</div>
</td>
</tr>
</table>
<?php
}
?>
and here is my up.php file
<?php
session_start();
include("config.php");
$ip=$_SERVER['REMOTE_ADDR'];
$mes_id1 = $_POST['key1'];
$mes_id2 = $_POST['key2'];
$totalvotes1 = $_POST['key3'];
$ip_sql=mysql_query("select ip_add from Voting_IP where mes_id_fk='$mes_id1' and ip_add='$ip'");
$count=mysql_num_rows($ip_sql);
$ip_sql2=mysql_query("select ip_add from Voting_IP where mes_id_fk='$mes_id2' and ip_add='$ip'");
$count2=mysql_num_rows($ip_sql2);
// if the user has already voted, execute script
if($count==0 && $count2!=0)
{
$sql = "update Messages set totalvotes=totalvotes+1 where mes_id='$mes_id1'";
mysql_query( $sql);
$sql_in = "insert into Voting_IP (mes_id_fk,ip_add) values ('$mes_id1','$ip')";
mysql_query( $sql_in);
$sql = "update Messages set totalvotes=totalvotes-1 where mes_id='$mes_id2'";
mysql_query( $sql);
$sql_in = "DELETE FROM Voting_IP WHERE mes_id_fk='$mes_id2'";
mysql_query( $sql_in);
// if the user has not voted, execute script
}
else if($count==0 && count2==0)
{
$sql = "update Messages set totalvotes=totalvotes+1 where mes_id='$mes_id1'";
mysql_query( $sql);
$sql_in = "insert into Voting_IP (mes_id_fk,ip_add) values ('$mes_id1','$ip')";
mysql_query( $sql_in);
}
?>
In your first Ajax request, for example, you have set the url to up.php
$.ajax({
type: "POST",
url: "up.php",
data: dataString,
cache: false,
success: function(html){
parent.html(html);
}
});
That means that you'll be retrieving data from up.php. The way that an Ajax request works is that ANY data displayed on the php page, after it's done loading, will be returned as a string to the page that sent the Ajax request.
In your up.php page, you have not put any echo statements or any html code. Thus there is no data in your success function being returned. Which makes parent.html(html) redundant.
You also cannot update variables on one php page from an Ajax request like you have specified. What you need to do is update the HTML data, or build the up.php page so that it returns a variable which you want to set to a Javascript variable in your success function....
i.e.
In up.php you must do the sql statement again, to retrieve the data that you want to change $message to and then echo that...
More or less like this: (very generalized I know)
$data = $_POST['ajaxRequestData'];
//do something with the data to create a new SQL statement
//do the sql statement and extract the value of $message that you're looking for
//THEN****
echo $message;
Next in your Ajax success function...
$.ajax({
type: "POST",
url: "up.php",
data: dataString,
cache: false,
success: function(data){
//here data will be equal to the value that you echoed in the up.php page.
//do whatever you want to do with it... You will not have access to the php variable on this page with Javascript.
//Server sided languages like PHP do not talk directly with client sided languages like Javascript except with Ajax.
updateMessage(data); //what I would do is create a function to send the variable to, to perform the necessary modifications to update your webpage.
}
});
//Note that as soon as the success function ends, the returned data is no longer available to you
//so you must pass it to a function (or a global variable) to be able to use it.
Fair warning: I am no expert, but I did manage to get this far. My code isn't beautiful and it is rough. It is a fairly complex system so don't be shy to ask questions.
So I have an annoying problem where my code works in chrome but nowhere else. It seems like none of my javascript is working in either Firefox or IE. PLEASE NOTE THAT EVERY TIME YOU SEE PHP INSIDE A DIV IT SIMPLY REPRESENTS THE # OF THE POST INSIDE THE DATABASE.
My code displays posts where each post is paired with a like and dislike button built with spans. There is a checkbox that shows/hides all liked posts and another that does the same for disliked posts when selected. When a user likes or dislikes a post by clicking the button, values are sent to my DB through ajax (to check.php) so they can be recalled on future visits.
Again, it all works fine in Chrome but not in IE and Firefox.
Also, unless I insert the values into my userPosts table in my database manually first, no new posts and values are saved in my DB. For example, if my DB already has values for posts 1-3, all future decisions by the user to like/dislike those posts are sent and saved no problem but if I add a new post (post4) and the user likes or dislikes it, no values get sent... it seems like the INSERT doesn't work in check.php whereas the UPDATE functions just fine.
Here is the jQuery that sits inside the loop, you should find it annotated to your satisfaction:
<script type="text/javascript">
$(document).ready(function() {
// Declare variables
var checked = <?php echo $row['value']; ?>; //get value of Liked or Disliked from database
var postID = <?php echo $row['postID']; ?>; //get post ID from database
var userID = <?php echo $current_user->ID; ?>; //get the wordpress user's ID
var showLikes = $("input[name*='show_likes']"); //represents checkbox for Hide Liked
var showDislikes = $("input[name*='show_dislikes']"); //represents checkbox for Hide Disliked
// Set the remembered Liked and Disliked buttons
if (checked == 1) {
$('#post_<?php echo $row['postID']; ?>').addClass('like');
$('#like_<?php echo $row['postID']; ?>').removeClass('likeimgoff').addClass('likeimgon');
} else if (checked == 0) {
$('#post_<?php echo $row['postID']; ?>').addClass('dislike');
$('#dislike_<?php echo $row['postID']; ?>').removeClass('dislikeimgoff').addClass('dislikeimgon');
}
//When Liked button is clicked do this
$('#like_<?php echo $row['postID']; ?>').click(function() {
// Declare variables
var value = '1';
// Send values to database
$.ajax({
url: 'check.php',
type: 'POST',
data: 'userID=' + userID + '&postID=' + postID + '&value=' + value,
success: function(result) {
$('#Message_<?php echo $row['postID']; ?>').html('').html(result).prependTo('#post_<?php echo $row['postID']; ?>');
}
});
// If post is Disliked, change to Liked
$('#post_<?php echo $row['postID']; ?>').removeClass('dislike').addClass('like');
$('#dislike_<?php echo $row['postID']; ?>').removeClass('dislikeimgon').addClass('dislikeimgoff');
$('#like_<?php echo $row['postID']; ?>').removeClass('likeimgoff').addClass('likeimgon');
// If Hide Liked checkbox is on, toggle the post
if (showLikes.attr('checked')) {
$('#post_<?php echo $row['postID']; ?>').toggle();
}
return false;
});
//When Disliked button is clicked do this
$('#dislike_<?php echo $row['postID']; ?>').click(function() {
// Declare variables
var value = '0';
// Send values to database
$.ajax({
url: 'check.php',
type: 'POST',
data: 'userID=' + userID + '&postID=' + postID + '&value=' + value,
success: function(result) {
$('#Message_<?php echo $row['postID']; ?>').html('').html(result).prependTo('#post_<?php echo $row['postID']; ?>');
}
});
// If post is Liked, change to Disliked
$('#post_<?php echo $row['postID']; ?>').removeClass('like').addClass('dislike');
$('#like_<?php echo $row['postID']; ?>').removeClass('likeimgon').addClass('likeimgoff');
$('#dislike_<?php echo $row['postID']; ?>').removeClass('dislikeimgoff').addClass('dislikeimgon');
// If Hide Disliked checkbox is on, toggle the post
if (showDislikes.attr('checked')) {
$('#post_<?php echo $row['postID']; ?>').toggle();
}
return false;
});
//When Hide Liked checkbox clicked, toggle all Liked posts.
$("input[name*='show_likes']").click(function() {
if ($('#post_<?php echo $row['postID']; ?>').is('.like')) {
$('#post_<?php echo $row['postID']; ?>').toggle();
}
});
//When Hide Disliked checkbox clicked, toggle all Disliked posts.
$("input[name*='show_dislikes']").click(function() {
if ($('#post_<?php echo $row['postID']; ?>').is('.dislike')) {
$('#post_<?php echo $row['postID']; ?>').toggle();
}
});
});
</script>
Here is the code for each post, also sitting in the loop followed by the #Message that appears when the ajax returns the output of check.php and finally closes the loop:
<div id="post_<?php echo $row['postID']; ?>" class="post">
<div id="post_<?php echo $row['postID']; ?>_inside" class="inside">
<div id="like">
<a id="like_<?php echo $row['postID']; ?>" class="likeimgoff" href="#"><span></span></a>
</div>
<div id="dislike">
<a id="dislike_<?php echo $row['postID']; ?>" class="dislikeimgoff" href="#"><span></span></a>
</div>
<b><?php echo $row['Title']; ?></b><br>
<?php echo $row['Description']; ?><br>
</div>
</div>
<div id="Message_<?php echo $row['postID']; ?>" class="reminder"></div>
<?php
}
?>
</div>
Here is check.php:
<?php
mysql_connect("name.database.com", "username", "password") or die(mysql_error());
mysql_select_db("databasename") or die(mysql_error());
if (isset($_POST['userID'])){
$userID = mysql_real_escape_string($_POST['userID']);
}else{
echo "No userID";
}
if (isset($_POST['postID'])){
$postID = mysql_real_escape_string($_POST['postID']);
}else{
echo "No postID";
}
if (isset($_POST['value'])){
$value = mysql_real_escape_string($_POST['value']);
}else{
echo "No value";
}
$query = mysql_query("SELECT * FROM userPosts WHERE userID='$userID' AND postID='$postID';") or die(mysql_error());
if (mysql_num_rows($query) > 0) {
mysql_query("UPDATE userPosts SET value='$value' WHERE userID='$userID' AND postID='$postID';") or die(mysql_error());
} else {
mysql_query("INSERT INTO userPosts (userID, postID, value) VALUES ('$userID', '$postID', '$value') ") or die(mysql_error());
}
echo "UserID: " .$userID. " PostID: " .$postID. " Value: " .$value;
?>
So there you have it. I know it is a lot of code, so please don't shy away and feel free to ask questions!
Sorry, I didn't took the time to read your whole post but usually this type of problems are of a javascript error. If you don't have it, install Firebug on Firefox and see in the firebug console if you have any errors, also look if the ajax call is made and what answer you get.