Jump to content

Archived

This topic is now archived and is closed to further replies.

just-j

html forms and php calling the variable?? *SOLVED*

Recommended Posts

ok i just got into PHP scripting and downloaded wamp server, which is mysql, php, and apache server  all in one nifty installation.  my problem is i make on file:

test1.html
....
<FORM ACTION="test2.php" method="post">
Type name here:
<input type="text" name="name">
<br>
<input type=submit value="Login"><br>
</FORM>
....

then other file
test2.php
<?
echo $name;
?>


and when i test it in the web browser it goes to the php page  but it just dosent echo anything..  ive been trying to figure this out for 2 days now...  HELP!!!!

Share this post


Link to post
Share on other sites
Read up on PHP basics so you don't get frustrated.

Change this:

echo $name;

to this:

echo $_POST['name'];

See:
http://us2.php.net/manual/en/reserved.variables.php

Share this post


Link to post
Share on other sites
You are probably using a book that assumes that the register_globals option is enabled. This was the default up until about 3 years ago when it was found that enabling register_globals can cause security problems. The default was changed to disabled and now to get the values from forms and URLs, you need to reference the appropriate superglobal array: $_POST for forms using the method="post" and $_GET for forms using method="get" and for variables on the URL. See http://www.php.net/register_globals

In your case you need to use:
[code]
<?php
echo $_POST['name'];
?>
[/code]

Ken

Share this post


Link to post
Share on other sites
i tried the $_post and still cant figure it out..  still getting a blank page when it goes to the php page.  this is what i have in the .php page as of now.

[code]
<html>
<head>
<title>Untitled Document</title>
</head>

<body>
<?
echo $_POST['name'];
?>
</body>
</html>
[/code]

i even tried to set the post name to a var. and then echoing it and still nothing is output to the browser.

Share this post


Link to post
Share on other sites
Maybe its echoing nothing because your host doesnt support php?

Share this post


Link to post
Share on other sites
You are using short tags "<?", your host may not have short tags enabled, try using "<?php" instead.

Ken

Share this post


Link to post
Share on other sites
Yes, but then he would see the code and not just a blank page.

Change your test2.php page to:

[code]
<?PHP
echo 'Name: ', isSet($_POST['name']) ? $_POST['name'] : 'Not set' ;

?>
[/code]

Make sure the test2.php is in the same directory as your html form.

Create this in a separate file and run it to see what your php settings are and it will tell you if your server and PHP are setup right:

[code]
<?PHP
phpinfo();
?>
[/code]

Share this post


Link to post
Share on other sites
[quote author=Kurt link=topic=99878.msg393612#msg393612 date=1152376227]
Maybe its echoing nothing because your host doesnt support php?
[/quote]
Read his/her post again carefully. You'll notice that it's a local installation.

Share this post


Link to post
Share on other sites
[quote author=toplay link=topic=99878.msg393616#msg393616 date=1152376481]
[quote author=Kurt link=topic=99878.msg393612#msg393612 date=1152376227]
Maybe its echoing nothing because your host doesnt support php?
[/quote]
Read his/her post again carefully. You'll notice that it's a local installation.
[/quote]
D'oh, :P
Maybe there were problems with his download or something? Or like kenrbnsn said, it could be that the server doesn't allow short style tags.

Share this post


Link to post
Share on other sites
man i love these forums!!  every one is so quick to reply.  it was the short tag <? problem  changed it to <?php and works perfect..  im back in learning business..  thanks everyone.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.