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,858 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
  • 3
  • 3
7 Comments
 
LVL 108

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 108

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 108

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
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.

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now