Welcome to WebmasterWorld Guest from 54.167.157.247

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Spot the parse error

   
4:19 pm on Jun 27, 2012 (gmt 0)

5+ Year Member



Error is (according to an error_log file):
PHP Parse error: syntax error, unexpected '{' in /process.php on line 1

And the supposedly offending line is in here. These are the first 4 lines in process.php


<?php
if ((isset($_POST['name'])) && (strlen(trim($_POST['name'])) > 0)) {
$name = stripslashes(strip_tags($_POST['name']));
} else {$name = 'No name entered';}


Everything makes sense...but yet it has an error...im confused :S
5:51 pm on Jun 27, 2012 (gmt 0)

10+ Year Member



A proper IDE will highlight syntax errors in your code and my Netbeans, along with my own eyes tell me there is no parse error here. Are you sure you're in the right file / script?
6:11 pm on Jun 27, 2012 (gmt 0)

5+ Year Member



Yep, very sure I'm in the right file. My code editor says there's no un-matched brackets, or open ' or ".

Why is it giving an error? Could there be an error later on in the script? Again, code editor says there's nothing wrong.

I use bluefish for linux with syntax highlighting on.
6:07 am on Jun 28, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you may have got one more '(' than ')' in your condition statement, which would throw off the parser when it encounters a '{' without a closing '}' before it finally finds a closing ')'.
6:38 am on Jun 28, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



(

(isset
($_POST['name'])
)

&&

(strlen

(trim
($_POST['name'])
)

> 0
)

)

Definately no mismatch.
10:47 am on Jun 28, 2012 (gmt 0)

5+ Year Member



I've given up, and gone another route for what I was doing. Maybe I should submit this to wikipedia under the "additions to the seven wonders of the world"...
8:36 pm on Jun 28, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



:: grasping at straws ::

Any chance you've got a wonky server that wants the opening { to be on a new line even though it should make no earthly difference?

:: Vague mental association with Jean "A space is a space" Chrétien ::
4:25 pm on Jun 29, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Although that would likely be a no, it does lead to one possibility - what was it edited in, and how was it uploaded? A scenario might be edited in MS Word and uploaded in binary, or some condition that messes with Unix carriage returns, it can do some odd things with line returns that may muck up the works - the latter is a prevalent problem in perl. If you open it in Notepad and see "black boxes" this could be the problem.

<highly unlikely, but given the seemingly impossible problem with the given example . . . >

You can also change && to the literal 'and' to see if it makes a difference (it shouldn't.)
8:37 pm on Jul 4, 2012 (gmt 0)

5+ Year Member



All good suggestions..but no previous problems with the server with similar code.

Code was edited, and made, in a code editor, bluefish (for linux), and uploaded via FireFTP to a linux server.

I've given up and found another solution anyway, but still, gives food for thought for those that have similar problems, or if I come across something like this again.

:)