• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4962
  • Last Modified:

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}'

Hi expert,

I've got this site that does not results in errors on my test server but does have errors on the production enviorment.
The error I get is:

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in sort_db.php on line 3

The code is beneath.

Please help me solve this problem.




<?
class SortableExample {
	protected $conn;
	protected $user = 'root';
	protected $pass = 'mypassword';
	protected $dbname = 'mydatabase';
	protected $host = 'localhost';
	public function __construct() {
		$this->conn = mysql_connect($this->host, $this->user, $this->pass);
		mysql_select_db($this->dbname,$this->conn);
	}
	public function getList() {
		$sql = "SELECT * FROM nieuws ORDER BY volgorde ASC, nieuwsID desc LIMIT 15";
		$recordSet = mysql_query($sql,$this->conn);
		$results = array();
		while($row = mysql_fetch_assoc($recordSet)) {
			$results[] = $row;
		}
		return $results;
	}
	public function updateList($orderArray) {
		$volgorde = 40;
		foreach($orderArray as $nieuwsID) {
			$nieuwsID = (int) $nieuwsID;
			$sql = "UPDATE nieuws SET volgorde={$volgorde} WHERE nieuwsID={$nieuwsID}";
			$recordSet = mysql_query($sql,$this->conn);
			$volgorde++;
		}
	}
}
?>

Open in new window

0
Steynsk
Asked:
Steynsk
  • 3
  • 3
1 Solution
 
Ray PaseurCommented:
Run phpinfo() on both servers and look to see any differences.

Is this all there is to the entire script?  I can't see why either server would have an issue with line 3 of this code.
0
 
SteynskAuthor Commented:
No you're right:

The total script is three PHP files and a java libary.

I'll have a look at the phpinfo() info

The complete PHP script is below:




----sort.php---------
<?
 
require('sort_db.php');
$demo = new SortableExample();
$list = $demo->getList();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>Zet de artikelen op volgorde.</title>
	<script src="../../lib/sort/prototype.js"></script>
	<script src="../../lib/sort/scriptaculous.js"></script>
	<script>
		Event.observe(window,'load',init,false);
		function init() {
			Sortable.create('listContainer',{tag:'div',onUpdate:updateList});
		}
		function updateList(container) {
			var url = 'sort_ajax.php';
			var params = Sortable.serialize(container.id);
			var ajax = new Ajax.Request(url,{
				method: 'post',
				parameters: params,
				onLoading: function(){$('workingMsg').show()},
				onLoaded: function(){$('workingMsg').hide()}
			});
		}
		function handleResponse(req) {
			// this function will fire after the ajax request is complete...but we have nothing to do here
		}
	</script>
</head>
<body>
<h2>Sorteren van nieuwsitems</h2>
Sleep de onderstaande titels in de gewenste volgorde. LET OP dit is direct ook de<br>volgorde waarop de titels worden getoond op de site.
<br>Bovendien worden uit de onderstaande berichten slechts de bovenste 10 op de website getoond. <br><br>
<div id="listContainer">
 
	<?
	$teller = 1;
	foreach($list as $item) {
		?>
		<div id="item_<?=$item['nieuwsID'];?>"><?= $teller." - ".date('d-m-Y', strtotime($item['plaatsingsdatum']))." - ".$item['titel'];?></div>
		<?
		$teller++;
	}
	?>
</div>
<div id="workingMsg" style="display:none;"><br><br>Database bijwerken...</div>
<p align=center><input type="button" value="Terug" onClick="location.href='../verkeersplein.php';"></p></td>
 
</body>
</html>
-------------end of sort.php---------------------
 
-------------sort_db.php---------------
<?
class SortableExample {
	protected $conn;
	protected $user = 'root';
	protected $pass = '';
	protected $dbname = 'zfc';
	protected $host = 'localhost';
	public function __construct() {
		$this->conn = mysql_connect($this->host, $this->user, $this->pass);
		mysql_select_db($this->dbname,$this->conn);
	}
	public function getList() {
		$sql = "SELECT * FROM nieuws ORDER BY volgorde ASC, nieuwsID desc  LIMIT 15";
		$recordSet = mysql_query($sql,$this->conn);
		$results = array();
		while($row = mysql_fetch_assoc($recordSet)) {
			$results[] = $row;
		}
		return $results;
	}
	public function updateList($orderArray) {
		$volgorde = 40;
		foreach($orderArray as $nieuwsID) {
			$nieuwsID = (int) $nieuwsID;
			$sql = "UPDATE nieuws SET volgorde={$volgorde} WHERE nieuwsID={$nieuwsID}";
			$recordSet = mysql_query($sql,$this->conn);
			$volgorde++;
		}
	}
}
?>
 
--------------------end of sort_db.php
 
------------------sort_ajax.php--------------
<?
session_start();
require('sort_db.php');
$demo = new SortableExample();
$demo->updateList($_POST['listContainer']);
?>
------------------end  of sort_ajax.php---------------------

Open in new window

0
 
SteynskAuthor Commented:
There is a large difference between the both versions.

The production is Version 4.4.7
The test is PHP Version 5.2.5

And a lot of configuration differences. What should I look for?

0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
Ray PaseurCommented:
PHP 4 and PHP 5 handle Object oriented programming VERY differently.  I am not even sure that PHP 4 can use the "protected" type of vars.

When are you planning to upgrade the production server to PHP5 (or php6)?  PHP4 is kind of dead now.
0
 
Hube02Commented:
PHP4 does not handle classes the same way as PHP5.

Basically you cannot use any of the public/private/protected stuff, this is where your error lies.

You will either need to remove it all or upgrade the server to PHP5. This is the main reason that I'm still not using the new features of PHP5 and must always code so that my work will run on PHP4. I never know what the environment will be.
0
 
SteynskAuthor Commented:
thanks
0
 
Ray PaseurCommented:
Thanks for the points - sorry there is not a better answer, but the good news is that the PHP4 to PHP5 transition is not too hard to get right, and the OOP features of PHP5 make life much better for all of us!  Best regards, ~Ray
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now