Jump to content

[SOLVED] This is Killing me


Brian W

Recommended Posts

I recently moved a project over to a new system running PHP v 5.2.6 (which I believe is the most recent "stable" version)

Suddenly, pages that used to work fine are having a common error, "unexpected $end"...

I go through and balanced the braces using Dreamweaver, then counting on my fingers, then I even found a neat site that you paste your script into and it highlights w/in the braces different colors... but all three tactics turned up nothing. The braces are 100% fine it appears. I think it has something to do with v 5.2.*, but I will give it the benefit of the doubt.

Is there any pieces of software out there that will check the integrity of your script? I've already spent hours on this and am tired of counting and recounting.

 

*I do NOT use the short tag ( "<?" ) ever.

*Using Dreamweaver, so I know I do not have a issue with my quotes because it comes of very clearly if I do.

*I will post the script if any one is interested in counting :-p (AKA, join my insanity)

 

Link to comment
Share on other sites

<?php require_once('../Connections/Test.php'); //Connection info ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "1,2";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) 
{ 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) 
{ 
      $isValid = true; 
    } 
    if (($strUsers == "") && false) 
{ 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "Dashboard.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO Clients (Client, Details) VALUES (%s, %s)",
                       GetSQLValueString($_POST['Client'], "text"),
                       GetSQLValueString($_POST['Details'], "text"));

  mysql_select_db($database_Test, $Test);
  $Result1 = mysql_query($insertSQL, $Test) or die(mysql_error());

  $insertGoTo = "Clients.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
  $updateSQL = sprintf("UPDATE Clients SET Client=%s, Details=%s, ClientID=%s WHERE ID=%s",
                       GetSQLValueString($_POST['Client2'], "text"),
                       GetSQLValueString($_POST['Details2'], "text"),
                       GetSQLValueString($_POST['ClientID'], "text"),
                       GetSQLValueString($_POST['hiddenField'], "int"));

  mysql_select_db($database_Test, $Test);
  $Result1 = mysql_query($updateSQL, $Test) or die(mysql_error());

  $updateGoTo = "Clients.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

if ((isset($_POST['DeleteID'])) && ($_POST['DeleteID'] != "")) {
  $deleteSQL = sprintf("DELETE FROM Clients WHERE ID=%s",
                       GetSQLValueString($_POST['DeleteID'], "int"));

  mysql_select_db($database_Test, $Test);
  $Result1 = mysql_query($deleteSQL, $Test) or die(mysql_error());

  $deleteGoTo = "Clients.php?Action=Deleted";
  if (isset($_SERVER['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $deleteGoTo));
}

mysql_select_db($database_Test, $Test);
$query_Clients = "SELECT * FROM Clients";
$Clients = mysql_query($query_Clients, $Test) or die(mysql_error());
$row_Clients = mysql_fetch_assoc($Clients);
$totalRows_Clients = mysql_num_rows($Clients);

$colname_Delete = "-1";
if (isset($_GET['ID'])) {
  $colname_Delete = $_GET['ID'];
  }
mysql_select_db($database_Test, $Test);
$query_Delete = sprintf("SELECT * FROM Clients WHERE ID = %s", GetSQLValueString($colname_Delete, "int"));
$Delete = mysql_query($query_Delete, $Test) or die(mysql_error());
$row_Delete = mysql_fetch_assoc($Delete);
$totalRows_Delete = mysql_num_rows($Delete);
?>
<?php //MAILER
if(isset($_GET['Action']) && $_GET['Action'] == "Deleted") { 
$To = 'Brian W <brianw@bexexpress.com>';
$Subject = 'Client "'.$_GET['Client'].'" has been removed.';
$Body = 'Client "'.$_GET['Client'].'" has been removed by '.$_SESSION['MM_Username'].'.';
	if(mail($To, $Subject, $Body)) {
		header('Location: Clients.php');
	}
}
?>
<!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>Dashboard - Manage Clients</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php include("top.php"); ?>
<?php 
$Show = "No";
if($row_LogedIn['Security'] == "1" && $_SERVER['REMOTE_ADDR'] == $row_LogedIn['IP']) 
{ $Show = "Yes"; }
if($row_LogedIn['Security'] == "2") 
{ $Show = "Yes"; }
if($Show == "Yes") { ?>
<a href="Dashboard.php">Back to Dashboard </a><a href="Test.php">Test</a><br />
  
  <?php //if Add
if(isset($_GET['Do']) && $_GET['Do'] == "Add") 
{ ?>
<h2>Add Client</h2>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <table width="100%" border="0" cellspacing="2" cellpadding="2">
    <tr>
      <td width="16%" valign="top"><div align="right"><strong>Client Name:</strong></div></td>
      <td width="84%">
        <input name="Client" type="text" id="Client" size="40" />
        </td>
    </tr>
    <tr>
      <td valign="top"><div align="right"><strong>Notes/ Details:</strong></div></td>
      <td>
        <textarea name="Details" id="Details" cols="75" rows="5"></textarea>

      </p></td>
    </tr>
    <tr>
      <td valign="top"><div align="right"><strong>Client ID:</strong></div></td>
      <td>
        <input type="text" name="ClientID2" id="ClientID2" />
<br />
          <input type="submit" name="Submit" id="Submit" value="Add Client" />
        </p></td>
    </tr>
  </table>

  <input type="hidden" name="MM_insert" value="form1" />
</form>

<p>
  <? } //if Add ?>
  <?php //if Add
if(isset($_GET['Do']) && $_GET['Do'] == "Delete" && $_GET['Client'] == $row_Delete['Client']) { ?>
<table width="68%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td class="update"><div align="center">
      <form id="form3" name="form3" method="post" action="">
        <input name="DeleteID" type="hidden" id="DeleteID" value="<?php echo $row_Delete['ID']; ?>" />
      Are you sure you want to delete Client "<strong><?php echo $row_Delete['Client']; ?></strong>"? 
      <input type="submit" name="Delete" id="Delete" value="Confirm Delete" />
      </form>
      </div></td>
  </tr>
</table>
<p>
<p>
  <?php } //if Delete ?>
<table border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="134" class="key">ID</td>
    <td width="308" class="key">Client</td>
    <td colspan="2" class="key">Client ID</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_Clients['ID']; ?>  </td>
      <td><a href="Clients.php?ID=<?php echo $row_Clients['ID']; ?>"> <?php echo $row_Clients['Client']; ?>  </a> </td>
      <td width="191" bordercolor="#CCCCCC"><?php echo $row_Clients['ClientID']; ?></td>
      <td width="109" bordercolor="#CCCCCC"> </td>
    </tr>
    <tr>
      <td colspan="4" class="spacer" height="5px">
  <?php if(isset($_GET['ID']) && $_GET['ID'] == $row_Clients['ID']) 
  {
  //If selected 
  ?>
      <form id="form2" name="form2" method="POST" action="<?php echo $editFormAction; ?>">
  <table width="100%" border="0" cellspacing="2" cellpadding="2" class="update">
        <tr>
          <td width="21%"><div align="right"><strong>Client Name:</strong></div></td>
          <td colspan="3">
            <input name="Client2" type="text" id="Client2" value="<?php echo $row_Clients['Client']; ?>" size="45" />
            </td>
        </tr>
        <tr>
          <td><div align="right"><strong>Notes/Details:</strong></div></td>
          <td colspan="2">
            <textarea name="Details2" id="Details2" cols="75" rows="6"><?php echo $row_Clients['Details']; ?></textarea>
          </td>
        </tr>
        <tr>
          <td valign="top"><div align="right"><strong>Client ID:</strong></div></td>
          <td width="63%">
            <input name="ClientID" type="text" id="ClientID" value="<?php echo $row_Clients['ClientID']; ?>" />
            <input name="hiddenField" type="hidden" id="hiddenField" value="<?php echo $row_Clients['ID']; ?>" />
            <br />
            <input type="submit" name="Submit2" id="Submit2" value="Update" />
          </td>
          <td width="16%" valign="bottom"><?php if($_SESSION['MM_UserGroup'] == "1"){ ?>
              <a href="?Do=Delete&ID=<?php echo $row_Clients['ID']."&Client=".$row_Clients['Client']; ?>">Delete</a>
              <?php } ?></td>
        </tr>
      </table>
       
          <input type="hidden" name="MM_update" value="form2" />
        </form>
      <?php } else { echo ""; }?></td>
    </tr>    
    <?php } while ($row_Clients = mysql_fetch_assoc($Clients)); ?>
    <tr>
      <td> </td>
      <td> </td>
      <td colspan="2" bordercolor="#CCCCCC"><div align="right"><a href="Clients.php?Do=Add">Add Client</a></div></td>
    </tr>
</table>
  <?php  }else{ ?> You have turned on the "Extra Security" setting for your account which disables the use of Express Project Manager from any other IP address than the one we have stored. Please contact ************* to have your account switched back to "Normal Security".  <?php } ?>
  <?php include("bottom.php") ?>
</body>
</html>
<?php
mysql_free_result($Clients);

mysql_free_result($Delete);
?>

 

-Top.php

 

<?php require_once('../Connections/Test.php'); ?><?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_LogedIn = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_LogedIn = $_SESSION['MM_Username'];
}
mysql_select_db($database_Test, $Test);
$query_LogedIn = sprintf("SELECT ID, Username, Client, `Level`, Email, Address, IP, Security FROM BexUsers WHERE Username = %s", GetSQLValueString($colname_LogedIn, "text"));
$LogedIn = mysql_query($query_LogedIn, $Test) or die(mysql_error());
$row_LogedIn = mysql_fetch_assoc($LogedIn);
$totalRows_LogedIn = mysql_num_rows($LogedIn);
?>
<link href="style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style4 {
font-family: brodyd
}
.style5 {
font-size: 24px;
color: #FF0000;
}
.style7 {
font-size: 12px;
color: #000000;
}

img {
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
}
-->
</style>
<table width="100%" height="118" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="37%" rowspan="2"><a href="Dashboard.php"><img src="logo.gif" width="329" height="139"></a><span class="style7">&#8482;</span></td>
    <td width="36%" valign="top"><p align="right"> </p>    </td>
    <td width="27%" valign="top"><?php if (isset($_SESSION['MM_Username'])){ ?><strong>Welcome:</strong> <?php echo $_SESSION['MM_Username']; ?><br /><a href="User.php?Name=<?php echo $_SESSION['MM_Username']; ?>">[Account Settings]</a><?php } else {?>Please <a href="../EPM/SignIn.php">Sign In</a>      <?php } ?></td>
  </tr>
  
  <tr>
    <td colspan="2" valign="bottom"><h3><span class="style4 style5">Dashboard</span><span class="style7">&#8482;</span></h3>
    <h1>Express Project Manager
      

      <?php $last = getenv("HTTP_REFERER");?></h1>    </td>
  </tr>
</table>
<?php
mysql_free_result($LogedIn);
?>
<?php if (isset($_GET['accesscheck'])) {?>
<p align="center"><strong>You do not have access to the page you were trying to view.</strong></p>
<?php } ?>

-bottom.php only has some html. It is our copyright statement and link to our company's website.

 

I think the script is pretty cluttered, but I guess that is what happens when you use Dreamweaver than go back and ad your own flavor.

BTW, this is not the only page having this problem. I don't understand whats going on, its just eating up time at this point.

Oh yeah, if I add a } after the last } in the code, the page doesn't work right but doesn't give me the error anymore/

Link to comment
Share on other sites

Is there any pieces of software out there that will check the integrity of your script?

 

To my knowledge, not entirely but I'm sure they're something out there to help.  I use NetBeans (free) and usually it can pick up mistakes, but besides that I'm not sure.

Link to comment
Share on other sites

I'm downloading NetBeans and I'll see if it can point me in the right direction. Thank you.

/b/ question... has any one else encountered this problem after moving to 5.2.*? Like I said, all I did was start using a different server for testing. I brought over all the exact same files.

*I went from 4.1.6 (I think it was) to 5.2.6

Link to comment
Share on other sites

Where though? It would appear that is the problem, but I haven't found any such problem.

If you mean the connection info page, there is not a single { or } in it. All it is is just my global variables for connecting to mysql.

 

Sorry, I would post the link, but two problems.

#1 - all you would see is

Parse error: syntax error, unexpected $end in C:\Inetpub\wwwroot\*censored*\Clients.php on line 295

#2 - It is actually already connected to our clients database and that information is private. Sorry...

Link to comment
Share on other sites

So, I'm going to go with "I'm screwed"... possibly I'll try reversing back to version 5.1.* or something and see if I continue to get the same problem. But please, if you refuse to believe this may be a problem with 5.2.6, keep counting, keep reviewing the code... if I don't figure this out in the next few hours, I'm downgrading. If downgrading fixes the problem, I will report this as a bug.

Link to comment
Share on other sites

http://www.balancebraces.com/  :D

I've made major changes to the script since the move in order to try to fix the error. But, what I will do is move the new copy back to the old server and see what it does. I'll let every one know how that goes.

 

There is a overwhelming amount of similar problems being discussed in other boards. Though some people are having odd and end problems of bad settings, actually missing the brace, or whatever... some people are stuck like I am.

 

Link to comment
Share on other sites

Which is not good for me... it is just bad practice to move on or avoid something instead of fixing a problem (no offense, speaking general). I want to do this the Linux & Mac way, not the Windows band-aid tactic...  :P

Still working at getting the old server back to functioning state so I can run that experiment on it...

Link to comment
Share on other sites

You say your script doesn't use short tags? Then what is this here:

<p>

  <? } //if Add ?>

  <?php //if Add

if(isset($_GET['Do']) && $_GET['Do'] == "Delete" && $_GET['Client'] == $row_Delete['Client']) { ?>

That is what is causing the error. Your previous server may of had a setting called short_open_tag enabled whereas your new server doesn't. Not all PHP setups have short tags enabled.

 

Also try to avoid letting Dreamwever write code for you. The code generated by DW is messy and can cause a lot of problems when trying to debug.

Link to comment
Share on other sites

Yeah, I agree with Maq... GOOD EYE! kudos comrade!

Thank you for finding that. Damn that was hard to find. I have the ini setting turned off purposely because I do not want to get in the habit of using short tags.

Again, Thank you wildteen88.

 

Well, I guess I was one of those people that I mentioned before that had petty little issues. *hits head on desk*

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.