Bien le bonjour à vous,

J'ai trouvé un code pour faire un système de vote, mais le soucis c'est que ça n'actualise pas ma bdd ...

je vous met les codes :

Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
		<?php 
 
$retour=mysqli_query($link, 'SELECT id, code, description, vote FROM posts ORDER BY id DESC LIMIT 0, 6');
 
			while($row = mysqli_fetch_assoc($retour)): ?>
 
			<div class="blocks"><!-- post data -->
 
	<iframe width="430" height="285" src="https://www.youtube.com/embed/<?php echo stripslashes($row['code']); ?>" frameborder="0" allowfullscreen></iframe> 
 
				<span>
				<form action="" method="post">
				<div data-postid="<?php echo stripslashes($row['id']); ?>" data-score="<?php echo stripslashes($row['vote']); ?>">
			<div class="vote-span"><!-- voting-->
				<div class="vote" data-action="up" name="up" title="Vote +">
					<i type="submit" class="icon-chevron-up"></i>
				</div><!--vote up-->
				<div class="vote-score"><?php echo $row['vote'] ?></div>
				<div class="vote" data-action="down" name="down" title="Vote -">
					<i type="submit" class="icon-chevron-down"></i>
				</div><!--vote down-->
			</div>
 
<?php echo $row['description']; ?>
			</div><!--item--></span>
			</div></form>
 
 
		<?php endwhile ?>

ça c'est le js :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* jQuery Voting System with PHP and MySQL
* @author Resalat Haque
* @link http://www.w3bees.com/2013/09/voting-system-with-jquery-php-and-mysql.html
*/
 
$(document).ready(function(){
	// ajax setup
	$.ajaxSetup({
		url: 'ajaxvote.php',
		type: 'POST',
		cache: 'false'
	});
 
	// any voting button (up/down) clicked event
	$('.vote').click(function(){
		var self = $(this); // cache $this
		var action = self.data('action'); // grab action data up/down 
		var parent = self.parent().parent(); // grab grand parent .item
		var postid = parent.data('postid'); // grab post id from data-postid
		var score = parent.data('score'); // grab score form data-score
 
		// only works where is no disabled class
		if (!parent.hasClass('.disabled')) {
			// vote up action
			if (action == 'up') {
				// increase vote score and color to orange
				parent.find('.vote-score').html(++score).css({'color':'orange'});
				// change vote up button color to orange
				self.css({'color':'orange'});
				// send ajax request with post id & action
				$.ajax({data: {'postid' : postid, 'action' : 'up'}});
			}
			// voting down action
			else if (action == 'down'){
				// decrease vote score and color to red
				parent.find('.vote-score').html(--score).css({'color':'red'});
				// change vote up button color to red
				self.css({'color':'red'});
				// send ajax request
				$.ajax({data: {'postid' : postid, 'action' : 'down'}});
			};
 
			// add disabled class with .item
			parent.addClass('.disabled');
		};
	});
});
et ça c'est le ajaxvote.php :

Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
 
require_once('config.php');
 
# start new session
session_start();
 
if ($_SERVER['HTTP_X_REQUESTED_WITH']) {
	if (isset($_POST['postid']) AND isset($_POST['action'])) {
		$postId = (int) mysqli_real_escape_string($_POST['postid']);
		# check if already voted, if found voted then return
		if (isset($_SESSION['vote'][$postId])) return;
		# connect mysql db
		dbConnect();
 
		# query into db table to know current voting score 
		$query = mysqli_query($link, "SELECT vote
			from posts
			WHERE id = '{$postId}' 
			LIMIT 1" );
 
		# increase or dicrease voting score
		if ($data = mysql_fetch_array($query)) {
			if ($_POST['action'] === 'up'){
				$vote = ++$data['vote'];
			} else {
				$vote = --$data['vote'];
			}
			# update new voting score
			mysqli_query($link, "UPDATE posts
				SET vote = '{$vote}'
				WHERE id = '{$postId}' ");
 
			# set session with post id as true
			$_SESSION['vote'][$postId] = true;
			# close db connection
			dbConnect(false);
		}
	}
}
?>

Voila ... je comprend pas pourquoi l'update ne se fait pas ... Merci de votre aide