By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,776 Members | 1,322 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,776 IT Pros & Developers. It's quick & easy.

First script - basic question

P: n/a
Hi,

I created an HTML page with the following code:
<html>
<body>
<form action="everif.php" method="post">
Name: <input type="text" name="name" size="12"><br>
First name: <input type="text" name="fname" size="12">
<input type="submit" value="OK">
</form>
</body>

</html>

and everif.php contains:
<?php
$fname= $_POST['fname'];
$name= $_POST['name'];
echo("<center>Hi $fname $name</center>");
?>
When I press OK from the HTML page 1 get:
Parse error: parse error, unexpected T_VARIABLE in
/var/www/free.fr/d/c/parispain/everif.php on line 2

where line 2 is:
$fname= $_POST['fname'];
Why?

Thank you.

Jul 17 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
> <?php
$fname= $_POST['fname'];
$name= $_POST['name'];
echo("<center>Hi $fname $name</center>");
?>
When I press OK from the HTML page 1 get:
Parse error: parse error, unexpected T_VARIABLE in
/var/www/free.fr/d/c/parispain/everif.php on line 2

where line 2 is:
$fname= $_POST['fname'];


I am not sure but first of all you should check if $_POST['fname']; is set .
so it should be somthing like :
if (isset($_POST['fname'])) $fname = $_POST['fname'];
else $fname = "";

the same for the $_POST['name']

Try that ... but then again I am not sure if it solves your problem!!!
Jul 17 '05 #2

P: n/a
> echo("<center>Hi $fname $name</center>");

And This is not going to echo your $fname and $name ...

Do that:
echo ("Hello".$fname." ".$name);
Jul 17 '05 #3

P: n/a
lo*************@yahoo.fr wrote:
(snip)
everif.php contains:
<?php
$fname= $_POST['fname'];
$name= $_POST['name'];
echo("<center>Hi $fname $name</center>");
?>

When I press OK from the HTML page 1 get:
Parse error: parse error, unexpected T_VARIABLE in
/var/www/free.fr/d/c/parispain/everif.php on line 2


Your code looks Ok to me. You don't need any brackets in the echo statement,
but it doesn't really matter.

Perhaps there's a problem with the line breaks in your PHP source. I think
PHP likes to see a carriage return and linefeed at the end of every line.
Some editors (especially on Mac systems) use carriage returns but no
linefeeds.

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/
Jul 17 '05 #4

P: n/a
Angelos wrote:
echo("<center>Hi $fname $name</center>");


And This is not going to echo your $fname and $name ...


Yes it is!

--
Oli

Jul 17 '05 #5

P: n/a
Philip Ronan wrote:
Perhaps there's a problem with the line breaks in your PHP source. I think PHP likes to see a carriage return and linefeed at the end of every line. Some editors (especially on Mac systems) use carriage returns but no
linefeeds.


Who told you that? You can write a whole PHP script all on line without
any newlines or carriage returns if you want.

--
Oli

Jul 17 '05 #6

P: n/a
On Tue, 17 May 2005 09:56:07 +0000 (UTC), Angelos wrote:
echo("<center>Hi $fname $name</center>");
And This is not going to echo your $fname and $name ...


Yes it is.
Do that: echo ("Hello".$fname." ".$name);


No, no need for that when using double quotes.
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #7

P: n/a
On Tue, 17 May 2005 11:12:10 +0100, Philip Ronan wrote:
<?php
$fname= $_POST['fname'];
$name= $_POST['name'];
echo("<center>Hi $fname $name</center>");
?>

When I press OK from the HTML page 1 get:
Parse error: parse error, unexpected T_VARIABLE in
/var/www/free.fr/d/c/parispain/everif.php on line 2


Your code looks Ok to me.


Me too. Did you copy and paste the code in your news post, or type it?
Your error could be from one space too many, for example after <? or $.
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #8

P: n/a
Oli Filth wrote:
Philip Ronan wrote:
Perhaps there's a problem with the line breaks in your PHP source. I

think
PHP likes to see a carriage return and linefeed at the end of every

line.
Some editors (especially on Mac systems) use carriage returns but no
linefeeds.


Who told you that? You can write a whole PHP script all on line without
any newlines or carriage returns if you want.


I just seem to recall having a few parse errors of my own before I set my
text editor up to use DOS line breaks.

I can't see what else could be wrong with the OP's script.

Can you?

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/
Jul 17 '05 #9

P: n/a
I cut and paste the script so I do not think additional spaces could be
the origin of the problem.
However, I *AM* using a Mac and it could be a carriage return issue...

Jul 17 '05 #10

P: n/a
On 17 May 2005 06:04:03 -0700, lo*************@yahoo.fr wrote:
However, I *AM* using a Mac and it could be a carriage return issue...


Yes, probably, if your server is not a Mac.
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #11

P: n/a
lo*************@yahoo.fr wrote:
I cut and paste the script so I do not think additional spaces could be
the origin of the problem.
However, I *AM* using a Mac and it could be a carriage return issue...


There are lots of decent free/shareware editors that might help. Try BBEdit
and JEdit, for example.

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/
Jul 17 '05 #12

P: n/a
OK,

The issue was just an uncorrect unicode space character replacing a
normal space, around an '=' sign.

Thank you very much,

Loc

Jul 17 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.