Search code examples
phpajaxvote

php/ajax vote up down


and sry in advance because i'm new here and i'm completly new in php/ajax coding.

I use a free script (Ajax vote up/down) from this site

I have a simple php page for my shoutcast server to show the song played

<?php
	
		require_once "inc.php";
	
	$array = array(); // Let's store our shoutcast variables into an array.
	
	$array['host'] = "xxx.xxx.xx.xxx"; // Your Shoutcast Host
	$array['port'] = "xxxx"; // Your Shoutcast Port
	$array['extra'] = "/admin.cgi?sid=1&mode=viewxml&page=1"; // The bit that follows in the url to access the xml of the stats
	$array['user'] = "xxxxx"; // Admin username (Default is usually "admin")
	$array['password'] = "xxxxxxx"; // Admin Password
	
    $radioStats = new radioStats( $array['host'], $array['port'], $array['extra'], $array['user'], $array['password']);
	 
    $returnStats = $radioStats->returnStats(); 
    $song = $returnStats['currentSong'];
     ?>
<div align="center">
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
 </script>
<link href="votingfiles/voting.css" rel="stylesheet" type="text/css" />
<script src="votingfiles/voting.js" type="text/javascript"></script>
 <script>
 $(document).ready(function(){
 setInterval(function(){cache_clear()},54000);
 });
 function cache_clear()
{
 window.location.reload(true);
}
</script>             
	<div id="radio_stats">

	<?php
		
		if( $returnStats['serverStatus'] != 0 ) {
		
	?>
		<?php
		if( $returnStats['currentSong'] != "" ) {
			echo $returnStats['currentSong'];
		} else {
			echo "Undefined";
		}
		?></div>
	
		<br /><br />
				<div class="vot_updown1" id="vt_$song"></div>	
	<?php
		}
		else {
	?>
	This radio server appears to be offline.
	<?php
		}
	?>

My problem is : All request Php/ajax/mysql works but actually when i make a vote, it's registered in the db like :

vt_$song 1 0

How can i do to get the real name of the song like the original php request do :

echo $returnStats['currentSong']; or echo $song;

To register in the db like :

vt_Kidd Guti-Step Everything 1 0 (or any other song played)

Example : [HERE]

Thanks in advance for any help.


Solution

  • In this line the $song is not parsed as PHP so the literal text $song is showing:

    <div class="vot_updown1" id="vt_$song"></div>
    

    Try:

    <div class="vot_updown1" id="vt_<?php echo $song; ?>"></div>