LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-10-2006, 10:10 AM   #1
frandalla
Member
 
Registered: Oct 2003
Location: Tokyo - Japan
Distribution: Slackware
Posts: 348
Blog Entries: 1

Rep: Reputation: 37
Question What's the meaning of "PHP Parse error: parse error, unexpected $ in..."


I've being working on a project and out of the blue I've being getting this error though it wasn't here a while before.

What's the exact meaning of this error?

PHP Parse error: parse error, unexpected $ in main.php on line 59
 
Old 04-10-2006, 10:33 AM   #2
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Line 59 has a $ where there shouldn't be one. In other words, it doesn't start a variable name. Common causes may be lack of semicolon to end previous line, or invalid variable name, or unescaped end-of-input anchor for a regular expression. If you can't locate it, go ahead and post that area of your code and I'll be happy to take a look at it.
 
Old 04-10-2006, 10:36 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
That means there was a '$' in the code in line 59 which should be there according to PHP's syntax.

For us to be of some help to you, please post the code or, if it's large, at least line 59 of file "main.php"...
 
Old 04-10-2006, 11:07 AM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
As HKO suggested please post the code or at least the appropriate lines say 50 - 70 (or the function boundary if that make sense.

Last edited by graemef; 04-10-2006 at 01:44 PM.
 
Old 04-10-2006, 12:15 PM   #5
frandalla
Member
 
Registered: Oct 2003
Location: Tokyo - Japan
Distribution: Slackware
Posts: 348

Original Poster
Blog Entries: 1

Rep: Reputation: 37
The point is: line 59 is the LAST line of the PHP code. Nothing last. It ends with a "}" on line 58 and 59 is a blank line.
I gotta leave very fast now. As soon as I get back I can post the whole code for you guys! thanks for the answers.

My guess: I think that $ means "end of line" (as in VI) and not a stray "$".
try to be back ASAP
 
Old 04-10-2006, 12:24 PM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
I disagree - I think the error means just what is says: that PHP found a "$" where there shouldn't be.

Before you post anything, please:
1. Comment out your PHP (to see if the problem goes away - it should!)
2. Put in some debug "echo" statements to see how far you get before the problem recurs

I believe you've probably got a bona fide syntax error in your PHP code, and I believe "divide and conquer" might be the best strategy to isolate and correct it.

IMHO .. PSM
 
Old 04-10-2006, 09:20 PM   #7
frandalla
Member
 
Registered: Oct 2003
Location: Tokyo - Japan
Distribution: Slackware
Posts: 348

Original Poster
Blog Entries: 1

Rep: Reputation: 37
I'm posting the code here for you.
I'm using php 5.0.5
Apache 2.0.55
I'm pretty sure there's no "$" hanging lost inside my code, I'm not such a beginner programmer.
Why am I guessing that?
This code used to work in my old linux installation. Now all files present me this very same error. I really don't know what to do.
PHP Code:
<?php
session_start
();
include(
"file.php");
$query="select * from user where user_name = '".$_POST['user']."';";
$link mysql_query($query);
$line mysql_fetch_array($link);
if((isset(
$_SESSION['pass']))||($line['user_pass'] == sha1($_POST['pass'])))
{
if(!isset(
$_SESSION['pass']))
{
$_SESSION['user'] = $_POST['user'];
$_SESSION['pass'] = $_POST['pass'];
}
?>
<html>
<head>
<script src="drop_down.js"> </script>
<style type="text/css">
@import "style.css";
</style>
</head>
<body  >
<div style="position:absolute;left:0%;top:2%">
<img src="images/webcontabil_small.png" alt="Logo" width="139" height="169" border="0">
<br><br><br>
<?//include("menu.php");?>
</div>
<?
if(!isset($_SESSION['emp_id']))
{
?>
<script language="javascript">
document.location.href="emp_sel.php";
</script>
</body>
</html>
<?
}
}
else
{
?>
<html>
<head>
<style type="text/css">
@import "style.css";
</style>
</head>
<body  >
<div style="position:absolute;left:50%;top:50%;margin-left:-100px;margin-top:-180px;" class="f">
<IMG src="images/webcontabil_small.png" alt="logo" width="126" height="171" border="0" style="margin-left:25px;"><br><br>
Senha Incorreta. Tente novamente.
</div>
</body>
</html>
<?
}
?>

Last edited by frandalla; 04-10-2006 at 09:31 PM.
 
Old 04-10-2006, 09:27 PM   #8
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
Before you post anything, please:
1. Comment out your PHP (to see if the problem goes away - it should!)
2. Put in some debug "echo" statements to see how far you get before the problem recurs

I believe you've probably got a bona fide syntax error in your PHP code, and I believe "divide and conquer" might be the best strategy to isolate and correct it.
I'd add to the list:
Quote:
3. Change your '<?' tags to '<?php'
4. Check your php.ini and see what happens if you enable "register globals"
My guess is that you're having problems with the older dialect of PHP on your new PHP 5.0 system.

Again: please modify the syntax and try the "divide and conqueror" approach (steps 2 and 2).

And please let us know what happens!

'Hope that helps .. PSM
 
Old 04-10-2006, 09:35 PM   #9
frandalla
Member
 
Registered: Oct 2003
Location: Tokyo - Japan
Distribution: Slackware
Posts: 348

Original Poster
Blog Entries: 1

Rep: Reputation: 37
My old installation was a 5.* PHP system.
I'll just try to rewrite the whole file and see what I can get. I have more than 10 files returning me the same error. Which was not here before. I wonder...
Any help will still be appreciated. Thanks to all who answered me. As soon as I have news I'll keep you up to date.
Quote:
Originally Posted by paulsm4
I'd add to the list:

My guess is that you're having problems with the older dialect of PHP on your new PHP 5.0 system.

Again: please modify the syntax and try the "divide and conqueror" approach (steps 2 and 2).

And please let us know what happens!

'Hope that helps .. PSM
 
Old 04-10-2006, 09:38 PM   #10
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Thoughts...

Double check that it is this file that is being read by php and not another file with the same name in a different directory (that sort of thing)
change <? to <?php
Add a liberal dose of echo statements so you know where you are

As an aside your code would appear to be open to a SQL injection attack
 
Old 04-11-2006, 07:35 AM   #11
frandalla
Member
 
Registered: Oct 2003
Location: Tokyo - Japan
Distribution: Slackware
Posts: 348

Original Poster
Blog Entries: 1

Rep: Reputation: 37
Guys, this error don't get me even to start running the file! It just gives the error. It's most likely what Paulsm4 said. Something that my old install of php recognized as OK and can't do it now. strange indeed is, as the system was a 10.2 slackware system too. As I told you, I'll try rewriting the whole file. I'll keep you informed.
 
Old 04-11-2006, 07:56 AM   #12
Spudley
Member
 
Registered: Mar 2003
Location: Berkshire, England.
Distribution: SuSE 10.0
Posts: 299

Rep: Reputation: 32
When you get this error on the last line of your PHP, it usually means that you left something unclosed -- ie mismatched brackets, php tags, or something like that. PHP freaks out because it gets to the end of the program and is expecting more code; it's reporting "unexpected $" because it treats the blank line after the final ?> as a print statement (ie print a carriage return).

As you say, it works in PHP4, and I don't have php5 on my box to test it with. Looking at the code, I can't see anything obviously wrong, but the line <?//include("menu.php");?> makes me wonder if php5 is treating the comment differently, and including the ?> in the comment, in which case, it would definitely cause problems. So maybe try changing that to use /*...*/ comment style instead.

I honestly can't see anything else that would cause problems. Hope you manage to solve it... If all else fails, split it down into bits, and see which one breaks.

All the best.
 
Old 04-11-2006, 10:13 AM   #13
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by frandalla
Guys, this error don't get me even to start running the file! It just gives the error.
Okay, just remove the contents of the file until it does work. Start with:

PHP Code:
<?php
echo "Hello";
?>
Just so you know it is using that file. Does that work?

Code:
if yes then
start adding lines of code maybe start with the first php block, that's about 15 lines.

Code:
else // it still didn't work
That probably means that it's not reading your file but another, just to be sure put an html only file in the same directory and try that.

graeme.
 
Old 04-11-2006, 11:54 AM   #14
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
It could be a problem in your included file (from the include() directive near the top) that's flowing over into this file. For example, a mis-matched parenthesis or bracket that's causing the parser to fail at the end of the whole input.
 
Old 04-11-2006, 12:29 PM   #15
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
frandalla - please do what graemef is suggesting. He's given a very good example of what I was calling "divide and conquer"; he's making the excellent point that maybe the failure isn't even occurring on the file you think it is. Graemef's advice also ties in well with taylor_venable's and spudley's equally well-considered suggestions.

Please try it and let us know what happens.
 
  


Reply

Tags
error, parser, php, programming



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Parse error" from class_postbit.php loading thread PTrenholme LQ Suggestions & Feedback 2 12-08-2005 11:26 AM
php send email parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expect jamesjoy Programming 7 12-06-2005 04:33 PM
PHP parse error unexpected '>' ldp Programming 2 03-04-2005 02:20 PM
kernel 2.6.0 compliation problems: "parse error before 'va_list'" sohmc Linux - General 6 12-21-2003 04:45 AM
Newbie: "Parse Error" when adding wireless usb network adapter tommer Red Hat 7 10-16-2003 04:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration