Jump to content

simple echo doesn' working


newbienewbie

Recommended Posts

<html>
<body>

Username:
<input name="username" type="text" size="10" maxlength="30" VALUE="This is my text username"/>
Password:
<input name="password" type="password" size="10" maxlength="4" />
<input type="submit" value="Login" />

<?php 
echo $_REQUEST['username'];
echo $_REQUEST['password'];
?>

</body>
</html>

 

echo $_REQUEST['username']; statement is not printing username value. why?

 

 

Link to comment
Share on other sites

You forgot the <form> tags. Try this and let me know if it works

 

<html>
<body>
<form action="" method="post">
Username:
<input name="username" type="text" size="10" maxlength="30" VALUE="This is my text username"/>
Password:
<input name="password" type="password" size="10" maxlength="4" />
<input type="submit" value="Login" />
</form>
<?php 
echo $_REQUEST['username'];
echo $_REQUEST['password'];
?>

</body>
</html>

Link to comment
Share on other sites

if you load that same page and at the end of your address MyPageName.php?username=Roboto&password=GodMode

 

You should get the responce your looking for..  However that is no way safe to be passing thru a password.

 

The page before shouel have..

 

$_SESSION['username'] = 'roboto' ;

$_SESSION['password'] = 'godmode' ;

 

 

The page you want to display it:

 

<?php

echo $_SESSION['username'].'<br>' ;

echo $_SESSION['password'] ;

?>

 

This way that critical information is not passed thru with a URL address.

Link to comment
Share on other sites

no luck . not working with form tag, not even with _SESSION and _POST. 

suggestions?

 

Well i used this code on my local server and it worked fine:

 

<html>
<body>
<form action="" method="post">
Username:
<input name="username" type="text" size="10" maxlength="30" VALUE="This is my text username"/>
Password:
<input name="password" type="password" size="10" maxlength="4" />
<input type="submit" value="Login" />
</form>
<?php 
echo $_REQUEST['username'];
echo $_REQUEST['password'];
?>

</body>
</html>

 

Are you running this on a local server or on a remote server (your hosting service)

Link to comment
Share on other sites

Check your version of PHP using phpinfo() ...

 

And if none of the previous code samples are working, no offense, I think you copied them wrong.  You have to hit submit, and the form action has to be "" so it reloads the same page.  The form method must be POST.

 

SESSION variables won't work unless you've started a session and created them.  And if this is truly a login form that will actually be used, and not just you goofing around, you'll want to learn sessions and how to create secure user authentication.  Google it.

 

If you're looking for on-the-fly displaying of the stuff you type into the box, you need both PHP and Javascript and create an Ajax call to update the page.  That's a lot of work for displaying what is already displayed on the page.

Link to comment
Share on other sites

try the code below:

 

<html>
<body>
<form action="" method="post">
Username:
<input name="username" type="text" size="10" maxlength="30" VALUE="This is my text username"/>
Password:
<input name="password" type="password" size="10" maxlength="4" />
<input type="submit" value="Login" />
</form>
<?php 
echo $_REQUEST['username'];
echo $_REQUEST['password'];
?>

</body>
</html>

 

 

hey, just enter some values for Username and Password columns and click on the Login button. You will get something printed ..sure... is it?

Link to comment
Share on other sites

Thanks you all,

 

when i entered values in username and password and click login button it displayed values. thanks again.

 

but newbie have questions, why it doesn't prints default value "This is my text username" on executing login.php form for the first time? why it prints value only after clicking login button?

 

 

Link to comment
Share on other sites

because you are using $_REQUEST method to print the value and the form has the method post. When the form gets submitted the value is posted and $_REQUEST finds that value and prints that. when the form is not submitted the $_REQUEST will not get anything untill you pass anything in querystring.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.