Vote for Items Ajax.php

Status
Not open for further replies.
Joined
Oct 28, 2010
Messages
888
Reaction score
115
Hi guys, well I've been trying to ages to try and fix it. I'm not that advanced in PHP but I can sort out a few problems and ****, but my main problem is this:


These are the 3 errored lines:

PHP:
$diff1 = diff($user['lastvote1']);
$diff2 = diff($user['lastvote2']);
$diff3 = diff($user['lastvote3']);


If you could help me I'd deeply appreaciate it.

FIXED

For those who dont know how to fix it:
Right click the ACCOUNT_TBL, click 'Design' then add the names 'lastvote1', 'lastvote2', 'lastvote3' in the collumn at the bottom, make the next section varchar(50), then make sure the tickbox does not have a tick in it. Then save the table. And done.
 
Last edited:
The Ajax.php's file content is:
PHP:
<?php
	include('./inc/config.inc.php');
	if(empty($_GET['page'])) $_GET['page'] = 1;
	
	/* VOTE BOX */
	if($_GET['a'] == 'showvotebox') {
		$_SESSION['votebox'] = 'showed';
	}
	
	if($_GET['a'] == 'hidevotebox') {
		$_SESSION['votebox'] = 'hidden';
	}
	
	if($_GET['a'] == 'voteitem') {
		$selecteditems = odbc_exec($mssql, 'SELECT * FROM [web_voteitems] WHERE vitemid=\''.mssql_escape_string($_GET['vid']).'\'');
		$selecteditem = odbc_fetch_array($selecteditems);
		odbc_exec($mssql, 'USE [ACCOUNT_DBF]');
		$userselect = odbc_exec($mssql, 'SELECT * FROM [ACCOUNT_TBL] WHERE account=\''.mssql_escape_string($_SESSION['user']).'\'');
		$user = odbc_fetch_array($userselect);
		
		if($user['cash'] < $selecteditem['price']) {
			echo '<span style="color: #f00;">You don\'t have enough Vote Points!</span><br/><br/>';
		} else {
			if(empty($_GET['char']) || !isset($_GET['char'])) {
				echo '<span style="color: #f00;">You must have a character!</span><br/><br/>';
			} elseif($selecteditem == '') {
				echo '<span style="color: #f00;">The selected item does not exist!</span><br/><br/>';
			} else {
				odbc_exec($mssql, 'USE [CHARACTER_01_DBF]');
				$accountofchar = odbc_exec($mssql, 'SELECT account FROM [CHARACTER_TBL] WHERE m_idPlayer=\''.mssql_escape_string($_GET['char']).'\'');
				if(strtolower(odbc_result($accountofchar, 'account')) == strtolower($_SESSION['user'])) {
					send_item($_GET['char'], $selecteditem['itemid'], $selecteditem['count']);
					odbc_exec($mssql, 'USE [ACCOUNT_DBF]');
					odbc_exec($mssql, 'UPDATE [ACCOUNT_TBL] SET cash=cash-\''.mssql_escape_string($selecteditem['price']).'\' WHERE account=\''.mssql_escape_string($_SESSION['user']).'\'');
					echo '<script type="text/javascript">currentvpoint(\''.$user['cash'].'\', \''.$selecteditem['price'].'\');</script>';
					echo 'You have successfully purchased the item!<br/><br/>';
				}
			}
		}
	}
	if($_GET['a'] == 'voteitemspage') {
		echo '<table>';
		odbc_exec($mssql, 'USE [WEBSITE_DBF]');
		$items = odbc_exec($mssql, 'SELECT * FROM [web_voteitems]');
		
		$page = $_GET['page'];
		$perpage = 2;
		$resultset = array();
		$counter = 0;
		while($row = odbc_fetch_array($items)) {
			$resultset[$counter++] = $row;
		}
		$count = odbc_exec($mssql, 'SELECT COUNT(*) as i FROM [web_voteitems]');
		$countpages = odbc_result($count, 'i') / $perpage;
		
		for($i = $perpage * ($page-1);$i < $perpage*$page;$i++) {
			if(isset($resultset[$i])) {
				echo '<tr>
					<td style="vertical-align: top;"><img src="./img/'.$resultset[$i]['icon'].'" /></td>
					<td valign="top">
						<b>'.$resultset[$i]['name'].'</b><br/>
						<table><tr><td><img src="img/price.png" /></td><td>'.$resultset[$i]['price'].' Vote Points</td></tr></table>';
					if(isset($_SESSION['user'])) {
						echo '<a href="javascript:voteItem('.$resultset[$i]['vitemid'].')">Take it!</a>';
					}
					echo '</td>
				</tr>
				<tr><td colspan="2"><br/></td></tr>';
			}
		}
		echo '</table>';
		for($i=0; $i < $countpages; $i++) {
			$k = $i + 1;
			if($page == $k) {
				 echo '<span id="page"><b>'.$k.'</b></span>';
			} else {
				echo '<span id="page"><a href="javascript:voteItemsPage('.$k.');">'.$k.'</a></span>';
			}
		}
	}
	if($_GET['a'] == 'voteitems') {
		echo 'Here you can vote for the server in order<br/>to support us and get a <b>free gift</b>!<br/><br/>';
		if(isset($_SESSION['user'])) {
			odbc_exec($mssql, 'USE [CHARACTER_01_DBF]');
			$player = odbc_exec($mssql, 'SELECT * FROM [CHARACTER_TBL] WHERE account=\''.mssql_escape_string($_SESSION['user']).'\' AND isblock=\'F\' ORDER BY playerslot');
			if(odbc_num_rows($player) >= 1) {
				echo 'Character: <form method="post"><select name="character" id="character">';
				while($char = odbc_fetch_array($player)) {
					echo '<option value="'.$char['m_idPlayer'].'">'.$char['m_szName'].'</option>';
				}
				echo '</select></form><br/>';
			}
		}
		echo 'Available Gifts:<br/><br/>
		<div id="availgifts">
		<table>';
		odbc_exec($mssql, 'USE [WEBSITE_DBF]');
		$items = odbc_exec($mssql, 'SELECT * FROM [web_voteitems]');
		$page = $_GET['page'];
		if(!isset($page)) { $page = 1; }
		$perpage = 2;
		$resultset = array();
		$counter = 0;
		while($row = odbc_fetch_array($items)) {
			$resultset[$counter++] = $row;
		}
		$count = odbc_exec($mssql, 'SELECT COUNT(*) as i FROM [web_voteitems]');
		$countpages = odbc_result($count, 'i') / $perpage;
		
		for($i = $perpage * ($page-1);$i < $perpage*$page;$i++) {
			if(isset($resultset[$i])) {
				echo '<tr>
					<td style="vertical-align: top;"><img src="./img/'.$resultset[$i]['icon'].'" /></td>
					<td valign="top">
						<b>'.$resultset[$i]['name'].'</b><br/>
						<table><tr><td><img src="img/price.png" /></td><td>'.$resultset[$i]['price'].' Vote Points</td></tr></table>';
					if(isset($_SESSION['user'])) {
						echo '<a href="javascript:voteItem('.$resultset[$i]['vitemid'].');">Take it!</a>';
					}
					echo '</td>
				</tr>
				<tr><td colspan="2"><br/></td></tr>';
			}
		}
		echo '</table>';
		for($i=0; $i < $countpages; $i++) {
			$k = $i + 1;
			if($page == $k) {
				 echo '<span id="page"><b>'.$k.'</b></span>';
			} else {
				echo '<span id="page"><a href="javascript:voteItemsPage('.$k.');">'.$k.'</a></span>';
			}
		}
		echo '</div><br />';
		if(isset($_SESSION['user'])) {
			odbc_exec($mssql, 'USE [ACCOUNT_DBF]');
			$cash = odbc_exec($mssql, 'SELECT cash FROM [ACCOUNT_TBL] WHERE account=\''.mssql_escape_string($_SESSION['user']).'\'');
			echo 'Current Vote Points: <b><span id="currvp">'.odbc_result($cash, 'cash').'</span></b><br/><br/>';
			echo '<span id="takeitem"></span>';
			echo '<a href="javascript:voteTab();"><b>Click here to vote!</b></a>';
		} else {
			echo '<b>You must login before you can vote!</b>';

		}
	}
	if($_GET['a'] == 'vote') { // Vote Box
		odbc_exec($mssql, 'USE [ACCOUNT_DBF]');
		$userselect = odbc_exec($mssql, 'SELECT * FROM [ACCOUNT_TBL] WHERE account=\''.mssql_escape_string($_SESSION['user']).'\'');
		$user = odbc_fetch_array($userselect);

		$diff1 = diff($user['lastvote1']);
		$diff2 = diff($user['lastvote2']);
		$diff3 = diff($user['lastvote3']);
		$votedtoday = 0;
		if($diff1['hours'] < 12)
			$votedtoday = $votedtoday + 1;
		if($diff2['hours'] < 12)
			$votedtoday = $votedtoday + 1;
		if($diff3['hours'] < 12)
			$votedtoday = $votedtoday + 1;
		echo 'Username: <b>'.$user['account'].'</b><br/><br/>';
		echo 'Current Vote Points: <b><span id="vpoints">'.$user['cash'].'</span></b><br/><br/>';
		echo 'You can vote <b><span id="vtoday"> '.(3 - $votedtoday).' </span></b> more times today.<br/><br/>';
		if($diff1['hours'] >= 12 || $diff2['hours'] >= 12 || $diff3['hours'] >= 12) {
			if(isset($_GET['submit'])) {
				if($_GET['submit'] == 1) {
					if($diff1['hours'] >= 12) {
						odbc_exec($mssql, 'UPDATE [ACCOUNT_TBL] SET cash=cash+\'1\', lastvote'.mssql_escape_string($_GET['submit']).'=\''.date('d.m.Y H:i:s').'\' WHERE account=\''.mssql_escape_string($_SESSION['user']).'\'');
					}
				} elseif($_GET['submit'] == 2) {
					if($diff2['hours'] >= 12) {
						odbc_exec($mssql, 'UPDATE [ACCOUNT_TBL] SET cash=cash+\'1\', lastvote'.mssql_escape_string($_GET['submit']).'=\''.date('d.m.Y H:i:s').'\' WHERE account=\''.mssql_escape_string($_SESSION['user']).'\'');
					}
				} elseif($_GET['submit'] == 3) {
					if($diff3['hours'] >= 12) {
						odbc_exec($mssql, 'UPDATE [ACCOUNT_TBL] SET cash=cash+\'1\', lastvote'.mssql_escape_string($_GET['submit']).'=\''.date('d.m.Y H:i:s').'\' WHERE account=\''.mssql_escape_string($_SESSION['user']).'\'');
					}
				}
			}
			echo 'You gain 1 Vote Point each topsite.<br/>After voting you will be able to choose a free gift!<br/>Follow the instructions to vote for all 3 topsites.<br/><br/><div id="topsite" style="text-align: center;">';
			if($diff1['hours'] >= 12) {
				// Top of Games
				echo '<img src="img/tog.gif" /><br/><br/>';
				echo '<span id="votetext"><a onclick="vote(1, '.$diff2['hours'].', \''.$votelist2.'\', \''.$votelist3.'\');" href="'.$votelist1.'" target="_blank">Click here to continue!</a></span>';
			} elseif($diff2['hours'] >= 12 ) {
				// Xtreme Top 100
				echo '<img src="img/xtop100.jpg" /><br/><br/>';
				echo '<span id="votetext"><a onclick="vote(2, '.$diff3['hours'].', \''.$votelist2.'\', \''.$votelist3.'\');" href="'.$votelist2.'" target="_blank">Click here to continue!</a></span>';
			} elseif($diff3['hours'] >= 12) {
				// G Top 100
				echo '<img src="img/gtop100.jpg" /><br/><br/>';
				echo '<span id="votetext"><a onclick="vote(3, 0, \''.$votelist2.'\', \''.$votelist3.'\');" href="'.$votelist3.'" target="_blank">Click here to continue!</a></span>';
			}
			echo '</div>';
		} else {
			echo '<a href="javascript:voteItemTab();">Choose an item!</a>';
		}
	}
	/* VOTE BOX END */
?>
 
I'm not sure about it, but I think that you need to create 3 news stored procedure on your database
named: lastvote1, lastvote2, lastvote3
 
For those who dont know how to fix it:
Right click the ACCOUNT_TBL, click 'Design' then add the names 'lastvote1', 'lastvote2', 'lastvote3' in the collumn at the bottom, make the next section varchar(50), then make sure the tickbox does not have a tick in it. Then save the table. And done.
 
Status
Not open for further replies.
Back