Jump to content

[SOLVED] Parse Error ???


woody79

Recommended Posts

This is the script:

<?php
$linkid = mysql_connect("localhost","usr","pwd");
$linkdb = mysql_select_db("tracker");
$result = mysql_query("SELECT * FROM login WHERE username='".md5($_SERVER['PHP_AUTH_USER'])."' AND password='".md5($_SERVER['PHP_AUTH_PW'])."'");
$number = mysql_num_rows($result);
if($number != 0) {
$trackid = 1;
}else{
$trackid = 0;
}
if($trackid == 1) {
function adduser() {
	global $linkid,$linkdb;
	$GLOBAL['valign'] = "middle";
	$halign = "center";
	if(isset($_POST['name']) && isset($_POST['username']) && isset($_POST['password'])) {
		$username = md5($_POST['username']);
		$password = md5($_POST['password']);
		$name = strtolower($_POST['name']);
		$sqlquery = "INSERT INTO login(name, username, password)";
		$sqlquery .= "VALUES('$name', '$username', '$password')";
		mysql_query($sqlquery);
		echo "<div align=\"center\" style=\"color:#ff0000;\">User Added Sucessfully!</div><br />";
	}else{
		?>
		<form action="<?php echo $_SERVER['PHP_SELF']; ?>?cmd=adduser" method="post">
		<table border="0">
			<tr>
				<td><strong>Full Name: </strong></td>
				<td><input type="text" name="name" /></td>
			</tr>
			<tr>
				<td><strong>Username: </strong></td>
				<td><input type="text" name="username" /></td>
			</tr>
			<tr>
				<td><strong>Password: </strong></td>
				<td><input type="password" name="password" /></td>
			</tr>
			<tr>
				<td colspan="2" align="right"><input type="submit" value="Add User" /></td>
			</tr>
		</table>
		</form>
		<?php
	}
}
function remuser() {
	global $linkid,$linkdb;
	if(isset($_GET['removename'])) {
		mysql_query("DELETE FROM login WHERE name='".$_GET['removename']."'");
		echo "<div align=\"center\" style=\"color:#ff0000;\">User Removed Sucessfully!</div><a href=\"".$_SERVER['PHP_SELF']."?cmd=vrecord\"></a>";
	}else{
		$remresult = mysql_query("SELECT * FROM login");
		$remnumber = mysql_num_rows($remresult);
		$remi = 0;
		if($remnumber == 0) {
			echo "<div align=\"center\" style=\"color:#ff0000;\">There appears to be no users to remove!</div><br />";
		}else{
			while($remnumber != $remi) {
				$remoutput = mysql_result($remresult,$remi,"name");
				list($remfirst, $remlast) = explode(" ", $remoutput);
				$remfirst = ucfirst($remfirst);
				$remlast = ucfirst($remlast);
				if(preg_match("/h:/i",$remoutput)) {
					echo "";
				}else{
					echo "<a href=\"".$_SERVER['PHP_SELF']."?cmd=remuser&removename=".$remoutput."\" class=\"remusr\">".$remfirst." ".$remlast."</a><br />";
				}
				$remi++;
			}
		}
	}
}
function vrecord() {
	global $linkid,$linkdb;
	if(!isset($_GET['uid'])) { 
		$recresult = mysql_query("SELECT * FROM tracker");
		$recnumber = mysql_num_rows($recresult);
		$reci = 0;
		if($recnumber == 0) {
			echo "<div align=\"center\" style=\"color:#ff0000;\">There appears to be nobody to track!</div><br />";
		}else{
			echo "<table border=\"0\">\n\t<tr style=\"background-color:#9999CC; font-family:Arial, Helvetica, sans-serif;\">\n\t\t<th>User</th>\n\t\t<th>IP Address</th>\n\t\t<th>Session Started</th>\n\t\t<th>Session Ended</th>\n\t\t<th>Path</th>\n\t\t<th>Actions</th>\n\t</tr>\n";
			while($recnumber != $reci) {
				$recoutput1 = mysql_result($recresult,$reci,"user");
				$recoutput2 = mysql_result($recresult,$reci,"ip");
				$recoutput3 = mysql_result($recresult,$reci,"timestamp");
				$recoutput4 = mysql_result($recresult,$reci,"endsession");
				$recoutput5 = mysql_result($recresult,$reci,"tracker");
				$recoutput6 = mysql_result($recresult,$reci,"uid");
				echo "\t<tr ".(($reci%2) ? "style=\"background-color:#CCCCCC;\"" : "style=\"background-color:#EEEEEE;\"").">\n\t\t<td><a href=\"mailto:".$recoutput1."@kolbe.wa.edu.au\">".$recoutput1."</a></td>\n\t\t<td>".$recoutput2."</td>\n\t\t<td>".$recoutput3."</td>\n\t\t<td>".$recoutput4."</td>\n\t\t<td>".$recoutput5."</td>\n\t\t<td align=\"center\"><a href=\"javascript: confirmDelete('?cmd=vrecord&uid=".$recoutput6."')\"><img src=\"edit-delete.png\" border=\"0\" /></a></td>\n\t</tr>\n";
				$reci++;
			}
			echo "</table>";
		}
	}else{
		mysql_query("DELETE FROM tracker WHERE uid='".$_GET['uid']."'");
		echo "<div align=\"center\" style=\"color:#ff0000;\">Tracker ID removed Sucessfully!</div><a href=\"".$_SERVER['PHP_SELF']."?cmd=vrecord\">Go Back To View Records</a><br />";
	}
}
function home() {
	global $linkid,$linkdb;
	$filenameh = "bulletin.php";
	if(!file_exists($filenameh)){
	$fdh = fopen ($filenameh , "w+");
	fclose($fdh);
	}
	$fdh = fopen ($filenameh, "r");
	$contentsh = fread ($fdh, filesize($filenameh));
	fclose ($fdh);
	echo $contentsh;
}
function edtblltn() {
	global $linkid,$linkdb;
	$textpost = stripslashes($_POST['bodytext']);
	$submitted = $_POST['submit'];
	$myFile = "bulletin.php";
	if($submitted == "Change") {
		$fh = fopen($myFile, 'w');
		fwrite($fh, $textpost);
		fclose($fh);
		$theData = $textpost;
	}else{
		$fh = fopen($myFile, 'r');
		$theData = fread($fh, filesize($myFile));
		fclose($fh);
	}
	?>
		<form method="post">
		<table width="100%" border="0">
		  <tr>
			<th align="left"><font color="#999999" size="+6" face="Arial, Helvetica, sans-serif">Edit Bulletin</font></th>
		  </tr>
		  <tr>
			<td align="center"><textarea cols="80" rows="16" name="bodytext" style="font-family:Arial, Helvetica, sans-serif; color:#000000; font-size:16px;"><?php echo $theData; ?></textarea></td>
	  </tr>
	  <tr>
		<td align="right"><input type="submit" name="submit" value="Change" /></td>
	  </tr>
	</table>
	</form>
<?php
}
function title() {
	if($_GET['cmd'] == "home") {
		print " - Home";
	}
	if($_GET['cmd'] == "vrecord") {
		print " - View Records";
	}
	if($_GET['cmd'] == "adduser") {
		print " - Add User";
	}
	if($_GET['cmd'] == "remuser") {
		print " - Remove User";
	}
	if($_GET['cmd'] == "edtblltn") {
		print " - Edit Bulletin";
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Web Tracker Admin<?php title(); ?></title>
<style type="text/css">
<!--
body, td, th {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
color: #000000;
}
table {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
color: #000000;
border:0;
}
.nav {
font-size:24px;
}
.nav td {
border-bottom:thin dashed #FFFFFF;
}
.nav a {
font-size:24px;
text-decoration:none;
color:#666666;
}
.nav a:hover {
font-size:24px;
color:#CCCCCC;
}
.main {
background-color:#333333;
}
-->
</style>
<script type="text/javascript">
function confirmDelete(delUrl) {
  if (confirm("Are you sure you want to delete this record?")) {
    document.location = delUrl;
  }
}
function nav(cell,guide) {
if(guide == true) {
	document.getElementById(cell).style.borderBottom='#CCCCCC thin dashed';
}else{
	document.getElementById(cell).style.borderBottom='thin dashed #FFFFFF';
}
}
</script>
</head>
<body bgcolor="<?php if($trackid == 1) { echo "#000000"; }else{ echo "#ffffff"; } ?>">
<?php
if($trackid == 1) {
?>
<table width="100%" align="center">
<tr valign="top">
	<td width="170"><table cellspacing="10" bgcolor="#FFFFFF">
			<tr>
				<td width="150" align="center"><img src="logo.png" /></td>
			</tr>
			<tr class="nav">
				<td valign="top" id="home"><a href="?cmd=home" onMouseOver="nav('home',1);" onMouseOut="nav('home',0);">Home</a></td>
			</tr>
			<tr class="nav">
				<td valign="top" id="vrec"><a href="?cmd=vrecord" onMouseOver="nav('vrec',1);" onMouseOut="nav('vrec',0);">View Records</a></td>
			</tr>
			<tr class="nav">
				<td valign="top" id="ausr"><a href="?cmd=adduser" onMouseOver="nav('ausr',1);" onMouseOut="nav('ausr',0);">Add User</a></td>
			</tr>
			<tr class="nav">
				<td valign="top" id="rusr"><a href="?cmd=remuser" onMouseOver="nav('rusr',1);" onMouseOut="nav('rusr',0);">Remove User</a></td>
			</tr>
			<tr class="nav">
				<td valign="top" id="edtb"><a href="?cmd=edtblltn" onMouseOver="nav('edtb',1);" onMouseOut="nav('edtb',0);">Edit Bulletin</a></td>
			</tr>
		</table></td>
	<td class="main" valign="<?php
						if($_GET['cmd'] == "home") {
							echo "top";
						}
						if($_GET['cmd'] == "vrecord") {
							echo "top";
						}
						if($_GET['cmd'] == "adduser") {
							echo "middle";
						}
						if($_GET['cmd'] == "remuser") {
							echo "top";
						}
						if($_GET['cmd'] == "edtblltn") {
							echo "middle";
						}
					?>"><table width="100%" height="100%" class="main">
			<tr>
				<td align="<?php
						if($_GET['cmd'] == "home") {
							echo "left";
						}
						if($_GET['cmd'] == "vrecord") {
							echo "center";
						}
						if($_GET['cmd'] == "adduser") {
							echo "center";
						}
						if($_GET['cmd'] == "remuser") {
							echo "center";
						}
						if($_GET['cmd'] == "edtblltn") {
							echo "center";
						}
					?>"><?php
						if($_GET['cmd'] == "home") {
							home();
						}
						if($_GET['cmd'] == "vrecord") {
							vrecord();
						}
						if($_GET['cmd'] == "adduser") {
							adduser();
						}
						if($_GET['cmd'] == "remuser") {
							remuser();
						}
						if($_GET['cmd'] == "edtblltn") {
							edtblltn();
						}
					?></td>
			</tr>
		</table></td>
</tr>
</table>
<?php
}else{
?>
<center>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
	<td align="center" valign="middle"><img src="logo.png" /><br /><div align="center" style="color:#FF0000; font-size:36px; font-weight:bold;">Entry Prohibited</div></td>
</tr>
</table>
</center>
<?php
}
?>
</body>
</html> //this is line 311

This is the Error:

Parse error: parse error in /Library/WebServer/www/intranet/tracker/index.php on line 311

I can't work out why it gives me an error. Can anyone please help?

By the way this is a tracking script and if you are looking for one, you can use this one. Works best with a realm.

Link to comment
Share on other sites

Hmmm, i haven't tried myself, but i dont think you can is if { then close the php code ?> then open it again and } .... etc, if you understand what im trying to say?

 

I think its generally good practice to build, or echo out html

 

what i always do is use a variable $body and go...

 

<?php

$body = "<html">;
if ($var == 1)
{ $body .= "sdcsdcsd"; }
else
{ $body .= "123123"; }
//... whatever other code
echo $body;
?>

 

maybe someone can tell me if this is all rubbish :)

Link to comment
Share on other sites

The problem is to do with line 11:

if($trackid == 1) {

There is no closing brace for that if. This is what is causing the error.

 

Where is the closing brace supposed to go. from looking at your code it should go on line 218 which is this:

<?php
if($trackid == 1) { // line 218
?>

 

Link to comment
Share on other sites

The problem is to do with line 11:

if($trackid == 1) {

There is no closing brace for that if. This is what is causing the error.

 

Where is the closing brace supposed to go. from looking at your code it should go on line 218 which is this:

<?php
if($trackid == 1) { // line 218
?>

 

 

Look carefully as it is being closed

Link to comment
Share on other sites

The problem is to do with line 11:

if($trackid == 1) {

There is no closing brace for that if. This is what is causing the error.

 

Where is the closing brace supposed to go. from looking at your code it should go on line 218 which is this:

<?php
if($trackid == 1) { // line 218
?>

 

 

Look carefully as it is being closed

On what line does it get closed? My PHP editor highlights matching pairs of curly braces. All braces match up apart from line 11.

Link to comment
Share on other sites

No, 308 closes the else block above it:

...

}else{

?>

<center>

<table border="0" cellpadding="0" cellspacing="0">

<tr>

<td align="center" valign="middle"><img src="logo.png" /><br /><div align="center" style="color:#FF0000; font-size:36px; font-weight:bold;">Entry Prohibited</div></td>

</tr>

</table>

</center>

<?php

}

?>

</body>

</html> //this is line 311

 

My advice is:

Go to http://notepad-plus.sourceforge.net/uk/site.htm

and download Notepad++ or any other syntax highlighter

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.