Forum Moderators: coopster
i want to pass username and password from one page to another.
my current code for second page where i need to access username and password is:
<?php
extract($_POST);
<?= $_POST['username']?>
?>
I am a beginner for PHP,Mysql.I found PHP is the most difficult scripting language compared to ASP. Please help me out.
Thanks!
milind
I'm assuming what you are trying to do. If I'm corrent, you are going to want to use sessions [us2.php.net] for this.
To initialize:
session_start();
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
To get variables on any other page:
session_start();
echo $_SESSION['username'];
echo $_SESSOIN['password'];
If I'm not correct in my assumption, then you have a syntax error:
<?php
extract($_POST);
echo $username;
?>
Good luck!
I am basically working for a Login Page. User will enter the Username and password & will be verified. The Login page transfer Username and password to another page(validation.php) to validate the user.
The connection with mysql is done on this page.Then the user is validated thr. a query of mysql.
Do you think i can work out in different way. Suggest simple method.
Really getting tough to work with php.
milind
By the way, Welcome to WebmasterWorld! (I was asleep for my last post) ;)
I think the code
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
doesn't work.
please reply me.
milind
login.php->
<html>
<body>
<form method="post" action="welcomepage.php">
First name: <input name="firstname" type="text" value=" ">
<br>
Last name: <input name="lastname" type="text" value=" ">
<br>
<br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
The other page is given below.
welcomepage.php->
<html>
<head>
<title>Handle Input</title>
</head>
<body>
<?php
global $firstname,$lastname;
$firstname = $_REQUEST["firstname"];
$firstname = $_REQUEST["lastname"];
echo "Hello";
if (!empty($firstname) &&!empty($lastname)) {
echo "Welcome ",$firstname," ",$lastname,"!";
}
else {
echo "Please first enter your name on the input form.";
}
?>
<br>
<br>
<a href="javascript: history.back()"><?php echo "$firstname";?>Back to Input Form</a>
</body>
</html>
Another thing i want to mention is, if i debug welcomepage.php the error comes: undefined index for firstname and lastname.
For this i got one solution. I changed the code in welcomepage.php:
$firstname = @_POST('firstname');
$lastname = @_POST('lastname');
Now the error is removed. But there is no output on the screen.
I will be really very much thankful if you could solve my problem now.
milind
use $_POST, your form is set to post so that is what you need to use
you aren't using session_start [php.net] on your welcomepage.php, you need to use session_start before any output so put it before your <html> tag.
>> undefined index for firstname and lastname.
this is just a notice so I am assuming that your error checking is set very high. Anytime you don't initialize a variable, you will get that notice.
your syntax is wrong here
$firstname = @_POST('firstname');
$lastname = @_POST('lastname');
it should look like this
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
If your php version is less than 4.1.0, would that cause an undefined index error for $_POST['firstname']?
You should get an undefined variable error.
Now my welcomepage.php code is :
<?php
session_start();
?>
<html>
<head>
<title>Handle Input</title>
</head>
<body>
<?php
global $firstname,$lastname;
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
echo "Hello";
if (!empty($firstname) &&!empty($lastname)) {
echo "Welcome ",$firstname," ",$lastname,"!";
}
else {
echo "Please first enter your name on the input form.";
}
?>
<br>
<br>
<a href="javascript: history.back()"><?php echo "$firstname";?>Back to Input Form</a>
</body>
</html>
But still not getting output.
I have installed php with the file:
php-4.4.4-installer.exe
Please reply.
sample1.php:
<html>
<body>
<form action="welcome.php" method="get">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
welcome.php:
<html>
<body>
Welcome <?php echo $_GET["name"];?>.<br />
You are <?php echo $_GET["age"];?> years old.
</body>
</html>
The output of this should be:
Welcome John.
You are 28 years old.
But i am getting the output:
Welcome .
You are years old.
Now i am not getting the error.
Do reply.
It ought to work on your system unless it is some setup problem - I see php-4.4.4-installer.exe which looks like windows because of the exe. Read php help regarding installation/setup?
PHP 4 for Windows comes in two flavours - a CGI executable (php.exe), and several SAPI modules (for example: php4isapi.dll) - php manual
I never used the CGI much -- I used the SAPI module -- actually I hardly use windows any more.
Uhh... dumb question... Do you have any php programs that work on this system, or is this the very first attempt on this system?
So concluding PHP as the most complicated among all other scripting languages!
Thanks for your reply.
milind