First script - basic question

This is a discussion on First script - basic question within the PHP Language forums, part of the PHP Programming Forums category; Hi, I created an HTML page with the following code: <html> <body> <form action="...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-17-2005
loic_e_bertrand@yahoo.fr
 
Posts: n/a
Default First script - basic question

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.

Reply With Quote
  #2 (permalink)  
Old 05-17-2005
Angelos
 
Posts: n/a
Default Re: First script - basic question

> <?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!!!


Reply With Quote
  #3 (permalink)  
Old 05-17-2005
Angelos
 
Posts: n/a
Default Re: First script - basic question

> echo("<center>Hi $fname $name</center>");

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

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


Reply With Quote
  #4 (permalink)  
Old 05-17-2005
Philip Ronan
 
Posts: n/a
Default Re: First script - basic question

loic_e_bertrand@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/


Reply With Quote
  #5 (permalink)  
Old 05-17-2005
Oli Filth
 
Posts: n/a
Default Re: First script - basic question

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

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


Yes it is!

--
Oli

Reply With Quote
  #6 (permalink)  
Old 05-17-2005
Oli Filth
 
Posts: n/a
Default Re: First script - basic question

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

Reply With Quote
  #7 (permalink)  
Old 05-17-2005
Ewoud Dronkert
 
Posts: n/a
Default Re: First script - basic question

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/
Reply With Quote
  #8 (permalink)  
Old 05-17-2005
Ewoud Dronkert
 
Posts: n/a
Default Re: First script - basic question

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/
Reply With Quote
  #9 (permalink)  
Old 05-17-2005
Philip Ronan
 
Posts: n/a
Default Re: First script - basic question

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/


Reply With Quote
  #10 (permalink)  
Old 05-17-2005
loic_e_bertrand@yahoo.fr
 
Posts: n/a
Default Re: First script - basic question

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...

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:36 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0