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
4,902 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 110

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 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 110

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

691 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