?
Solved

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

Posted on 2009-05-15
7
Medium Priority
?
4,915 Views
Last Modified: 2013-12-12
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
Comment
Question by:Steynsk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24399107
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
 
LVL 1

Author Comment

by:Steynsk
ID: 24399236
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
 
LVL 1

Author Comment

by:Steynsk
ID: 24399622
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 real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 24399662
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
 
LVL 18

Expert Comment

by:Hube02
ID: 24400051
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
 
LVL 1

Author Closing Comment

by:Steynsk
ID: 31582078
thanks
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24403680
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question