Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

small question from newbie

Status
Not open for further replies.

cazellnu

Technical User
Aug 15, 2002
41
CA
Guys and Gals:

I am trying to learn php from some books and I had some problem. It will be apperciate if someone can tell me what's wrong with the following syntax

<FORM>
Please type your name here: <BR>
<INPUT TYPE=TEXT NAME=username><BR><BR>
<INPUT TYPE=SUBMIT VALUE=&quot;SUBMIT DATA&quot;>
</FORM>

You Typed:
<?php echo ($username) ; ?>

When I typed something in the browser (in the textbox field&quot; and hit submit data, it directly me to ../abc.php?username=abcde; however, there were nothing was being printed after &quot;You Typed: &quot;. Please help!!!
 
You don't need the ().

echo $username;

I would also recommend putting quotes around the other attributes in the form ie type=&quot;text&quot;. It's proper form, and while most browsers won't throw an error with it, if you ever want to be xml or wam enabled you might as well get into the habit now.
 
I think MrBelfry is right. However your code ain't rly nice either

Try this
Code:
<FORM action=&quot;<?php echo($_SERVER['PHP_SELF']); ?>&quot; method=&quot;post&quot;>
    Please type your name here: <BR>
    <INPUT TYPE=TEXT NAME=username><BR><BR>
    <INPUT TYPE=SUBMIT VALUE=&quot;SUBMIT DATA&quot;>
</FORM>

You Typed:
<?php
   echo ($_POST['username']); 
?>

Differences:
A. I specify an action in <FORM> so the form knows where to submit to. In this case I submit to $_SERVER['PHP_SELF'], which is the php_script itself.

B. I specify a method in <FORM>. In this case I chose POST. In POST the variables aren't send through the uri like myscript.php?name=myname but hidden, which in this case seems more appropriate. If you want them in the uri use method GET

C. If register_globals is of your form variables aren't automagically returned in variables (e.g. $username). This is a security feature and the default setting of php has been changed from on to off.
To access variables submitted through method POST use the array $_POST, for method GET use $_GET
 
Be aware that according to the error reporting settings of you PHP installation you might receive an error when a non-existant key in an array (like $_POST['username']) is accessed.

The register_globals issue is unfortunately still a common question since older books etc. were written under the assumption that register_globals is on. PHP developers have learned that this is not a good idea and the security concern resulted in register_globals to be off since PHP 4.2.0

Read:

Follow herman75's suggestions to create valid HTML that provides the attributes form the <form> tag. According to the latests standards HTML tags are all lower case with attributes in double quotes.
 
I had tried both code from MrBelfry and herman75. I encounter the following error when I rn Mr.Belfry's code, &quot;Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in....&quot;. I wonder if my code was not working due to some configuration of my php.ini becasue my code is copy directly from the textbook but not working in my work. The following is part of my php.ini that related to the global_variable:

variables_order = &quot;EGPCS&quot;
register_globals = on
register_argc_argv = On
post_max_size = 8M
gpc_order = &quot;GPC&quot;

p.s. I am currently using PHP4 and it will be apperciate if anyone would offer help...Thank You =)
 
sleipnir214:

I am currently using PHP4.3.4 and Apache2.0 installed on Win2k Platform.

Thanks
 
Hmm a parse-error. That usually suggests a typo at the line-number it mentions or the line above. Check for unmatched bracket-pairs and missing ; at teh end of a line for the mentioned line-number and the line(s) directly above.

If you use PHP4.3.4 register global will probably be turned off
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top