Hi,
I'm new to coding and downloaded an old game script to try to teach myself and have been watching and taking lessons from codeschool, I can not with my knowledge work out what is wrong with this line:
echo 'ยซ <a href="http://'.$_SERVER['PHP_SELF'].'?act=add" target="_blank">Add Game</a> ยป
I recieve this error message: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/****/public_html/5050.php on line 86.
Here is the full code, could you please not just tell me what to do but EXPLAIN it so I learn from my mistakes ๐ Thanks so much!
<?php
require_once("globals.php");
class chance extends headers {
public $error = array();
public $minbet = 1;
public $maxbet = 1000;
public $maxgames = 10;
public function _back()
{
echo '<a href="http://javascript<b></b>: history.go(-1)" target="_blank">Back</a>';
}
public function _errors($error)
{
if (!empty($error))
{
echo'The following errors occured';
foreach ($error as $er)
{
echo ''. $er;
}
unset($error);
$this->_back();
$this->endpage();
exit;
}
}
public function _fetchUser($col)
{
$SQL = sprintf("SELECT `". $col ."` FROM `users` WHERE `userid` = %u", $_SESSION['userid']);
$exe = mysql_query($SQL);
$fetch = mysql_fetch_array($exe);
return $fetch[$col];
}
public function _add()
{
if(isset($_POST['submit']))
{
if (preg_match("/[^0-9]/i", $_POST['amt']))
{
$this->error[] = 'Amount must be numeric';
}
if($_POST['amt'] < $this->minbet)
{
$this->error[] = 'The minimum bet is '. $this->minbet;
}
$SQL = sprintf("SELECT COUNT(`logID`) amount FROM `chance` WHERE `userID` = %u AND `active` = 1", $this->_fetchUser('userid'));
$exe = mysql_query($SQL);
$check = mysql_fetch_array($exe);
if($check['amount'] >= $this->maxgames)
{
$this->error[] = 'There is a maximum of '. $this->maxgames;
}
if($_POST['amt'] > $this->_fetchUser('money'))
{
$this->error[] = 'You cannot afford that amount.';
}
$this->_errors($this->error);
$SQL_2 = sprintf("UPDATE `users` SET `money` = `money` - %u WHERE `userid` = %u",
$_POST['amt'],
$this->_fetchUser('userid'));
mysql_query($SQL_2);
$SQL_3 = sprintf("INSERT INTO `chance` (`logID`, `userID`, `amount`, `active`)
VALUES (NULL, %u, %u, 1)", $this->_fetchUser('userid'), $_POST['amt']);
mysql_query($SQL_3);
echo 'Your game has been set. Good Luck.';
}
else
{
echo 'Adding a game
<form action="'.$_SERVER['PHP_SELF'].'?act=add" method="POST">
Cash: <input type="text" name="amt" size="10" maxlength="10" />
<input type="submit" name="submit" value="Add!"></form>
ยซ '. $this->maxgames .' games max per user ยป';
}
}
public function _view_games()
{
$SQL = "SELECT t.* , u.username FROM `chance` t LEFT JOIN `users` u on u.userid = t.userID WHERE t.active = 1 ORDER BY t.logID ASC";
$exe = mysql_query($SQL);
echo 'ยซ <a href="http://'.$_SERVER['PHP_SELF'].'?act=add" target="_blank">Add Game</a> ยป
Table of users awaiting a challenge
<table width="75%">
<tr>
<td><u>Game ID</u></td>
<td><u>User</u></td>
<td><u>Amount</u></td>
<td><u>Challenge</u></td>
<td><u>Cancel</u></td>
</tr>';
while($r = mysql_fetch_array($exe)) {
echo '<tr>
<td>'. $r['logID'] .'</td>
<td><a href="http://viewuser.php?u='. $r['userID'] .'" target="_blank">'. $r['username'] .'</a> ['. $r['userID'] .']</td>
<td>'. $r['amount'] .'</td>
<td><a href="http://'. $_SERVER['PHP_SELF'] .'?act=challenge&ID='. urlencode($r['logID']) .'" target="_blank">Challenge</a></td>
<td>';
if($this->_fetchUser('userid') == $r['userID']){ echo '<a href="http://'. $_SERVER['PHP_SELF'] .'?act=cancel&ID='. urlencode($r['logID']) .'" target="_blank">Cancel</a>'; }************
echo '</td>
</tr>';
}
echo '</table>';
}
public function _challenge() {
*****
****$SQL = sprintf("SELECT t.*, u.username FROM `chance` t LEFT JOIN `users` u ON t.userID = u.userid WHERE t.logID = %u AND t.active = 1 LIMIT 1", $_GET['ID']);
****$exe = mysql_query($SQL);
****$fetch = mysql_fetch_array($exe);
*****
****if(!empty($fetch['logID'])) {
*
********if($fetch['amount'] > $this->_fetchUser('money')){ $this->error[] = 'You cannot afford the challenge amount.'; }
********if($this->_fetchUser('userid') == $r['userID']){ $this->error[] = 'You cannot accept your own challenge.'; }
********$this->_errors($this->error);
*********
********if(mt_rand(1,2) == 1) {
************$winner = $fetch['userID'];
************$loser = $this->_fetchUser('userid');
************$winnername = $fetch['username'];
************$losername = $this->_fetchUser('username');
************$string = '<font color="red">Sorry, you Lost. Better luck next time.</font>';
************$SQL_2 = sprintf("UPDATE `users` SET `money` = `money` - %u WHERE `userid` = %u", $fetch['amount'], $this->_fetchUser('userid'));
************$SQL_3 = sprintf("UPDATE `users` SET `money` = `money` + (%u * 2) WHERE `userid` = %u", $fetch['amount'], $fetch['userID']);
************mysql_query($SQL_2);
************mysql_query($SQL_3);
********}
********else {
************$winner = $this->_fetchUser('userid');
************$loser = $fetch['userID'];
************$winnername = $this->_fetchUser('username');
************$losername = $fetch['username'];
************$string = 'You Won! Congratulations!
<font color="green"> You Won '. money_formatter($fetch['amount']) .'!</font>';
************$SQL_4 = sprintf("UPDATE `users` SET `money` = `money` + %u WHERE `userid` = %u", $fetch['amount'], $this->_fetchUser('userid'));
************mysql_query($SQL_4);
********}
********event_add($winner, 'The game of '. money_formatter($fetch['amount']) .' challenged by <a href="http://viewuser.php?u= '. urlencode($this->_fetchUser('userid')) .'" target="_blank">'. $this->_fetchUser('username') .'</a>
********was won by <a href="http://viewuser.php?u='. urlencode($winner) .'" target="_blank">'. $winnername .'</a>.', $t);
********event_add($loser, 'The game of '. money_formatter($fetch['amount']) .'* challenged by <a href="http://viewuser.php?u='. urlencode($this->_fetchUser('userid')) .'" target="_blank">'. $this->_fetchUser('username') .'</a>
********was won by <a href="http://viewuser.php?u='. urlencode($winner) .'" target="_blank">'. $winnername .'</a>.', $t);
********$SQL_5 = sprintf("UPDATE `chance` SET `active` = 0 WHERE `logID` = %u", $_GET['ID']);
********mysql_query($SQL_5);
********echo $string;
****}
****else{ echo 'This game has either been cancelled or someone played before you got the 5050.'; }
}
*
public function _cancel() {
*
****$SQL = sprintf("SELECT `amount` from `chance` where `logID` = %u AND `active` = 1", $_GET['ID']);
****$exe = mysql_query($SQL);
****$fetch = mysql_fetch_array($exe);
*****
****if(!empty($fetch['amount']))
****{
********$SQL_2 = sprintf("UPDATE `users` SET `money` = `money` + %u WHERE `userid` = %u", $fetch['amount'], $this->_fetchUser('userid'));
********$SQL_3 = sprintf("UPDATE `chance` SET `active` = -1 WHERE `logID` = %u", $_GET['ID']);
********mysql_query($SQL_2);
********mysql_query($SQL_3);
********echo 'The game has been cancelled, and your money has been returned.';
****}
****else { echo 'This game has already been canceled, does not exist, or someone already played.'; }
*
}
}
*
$cha = new chance();
*
echo '<h1>50 / 50 money Game</h1>';
*
switch($_GET['act']) {
****case 'cancel': $cha->_cancel(); break;
****case 'challenge': $cha->_challenge(); break;
****case 'add': $cha->_add(); break;
****default: $cha->_view_games(); break;
}
*
?>