Jump to content


Photo

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


  • Please log in to reply
9 replies to this topic

#1 just-j

just-j
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts

Posted 08 July 2006 - 03:53 PM

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

#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 08 July 2006 - 03:59 PM

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/m...d.variables.php


#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 08 July 2006 - 03:59 PM

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:
<?php
echo $_POST['name'];
?>

Ken

#4 just-j

just-j
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts

Posted 08 July 2006 - 04:28 PM

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.

<html>
<head>
<title>Untitled Document</title>
</head>

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

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

#5 Kurt

Kurt
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts
  • LocationNew York

Posted 08 July 2006 - 04:30 PM

Maybe its echoing nothing because your host doesnt support php?

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 08 July 2006 - 04:32 PM

You are using short tags "<?", your host may not have short tags enabled, try using "<?php" instead.

Ken

#7 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 08 July 2006 - 04:33 PM

Yes, but then he would see the code and not just a blank page.

Change your test2.php page to:

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

?>

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:

<?PHP
phpinfo();
?>


#8 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 08 July 2006 - 04:34 PM

Maybe its echoing nothing because your host doesnt support php?

Read his/her post again carefully. You'll notice that it's a local installation.

#9 Kurt

Kurt
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts
  • LocationNew York

Posted 08 July 2006 - 04:43 PM

Maybe its echoing nothing because your host doesnt support php?

Read his/her post again carefully. You'll notice that it's a local installation.

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.

#10 just-j

just-j
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts

Posted 08 July 2006 - 04:58 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users