Forum Moderators: coopster

Message Too Old, No Replies

How to pass parameters?

Still need Help

         

opelit

10:12 am on Sep 28, 2006 (gmt 0)

10+ Year Member



Hi!
I have tried to use extract($_POST);
to solve my problem. But it still shows error.
parse error: parse error, unexpected <

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

eelixduppy

11:14 am on Sep 28, 2006 (gmt 0)



>>>I want to pass username and password from one page to another.

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!

opelit

11:50 am on Sep 28, 2006 (gmt 0)

10+ Year Member




Thanks for your prompt reply!

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

eelixduppy

1:26 pm on Sep 28, 2006 (gmt 0)



This thread [webmasterworld.com] taken from our Library [webmasterworld.com] explains this topic in detail. This will be very helpful for you.

By the way, Welcome to WebmasterWorld! (I was asleep for my last post) ;)

opelit

2:00 pm on Sep 28, 2006 (gmt 0)

10+ Year Member




Hi!
Sorry i have a doubt.
I am trying a sample example. I am passing firstname and password from one page to another and just displaying it on other one.
I am using available code.

I think the code
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
doesn't work.

please reply me.
milind

lmo4103

2:28 pm on Sep 28, 2006 (gmt 0)

10+ Year Member



I have used

$firstname = $_REQUEST["firstname"];

and it has worked whether the request was POST or GET.

opelit

2:56 pm on Sep 28, 2006 (gmt 0)

10+ Year Member




Hi!
Thanks for your kind help. But now i am getting very much frustrated with this php. Please do me a favor. I have added the code of both the pages here. Currently when i enter firstname and lastname and click login button, welcomepage.php is displayed but the output is blank.
The firstname and lastname are not displayed.
Please check it out.

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

lmo4103

3:05 pm on Sep 28, 2006 (gmt 0)

10+ Year Member



>>
$firstname = $_REQUEST["firstname"];
$firstname = $_REQUEST["lastname"];
<<

2 1st names?

Server variables: $_SERVER
Note:
Introduced in 4.1.0. In earlier versions, use $HTTP_SERVER_VARS. - php manual
(Predefined variables)

Php version >= 4.1.0?

jatar_k

6:01 pm on Sep 28, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you shouldn't use $_REQUEST, it allows for too many variables as far as intrusion goes.

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'];

lmo4103

8:06 pm on Sep 28, 2006 (gmt 0)

10+ Year Member



HTTP POST variables: $_POST
Note:
Introduced in 4.1.0. In earlier versions, use $HTTP_POST_VARS. -php manual

If your php version is less than 4.1.0, would that cause an undefined index error for $_POST['firstname']?

eelixduppy

9:16 pm on Sep 28, 2006 (gmt 0)




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.

opelit

5:51 am on Sep 29, 2006 (gmt 0)

10+ Year Member




Hi!
Really feeling good to see your reply.I hope you will solve my problem.Thanks for your help!

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.

opelit

11:55 am on Sep 29, 2006 (gmt 0)

10+ Year Member




Hi!
Thanks for your all reply.
I really need your help.
See now i am trying a very simple example.
The code is given below:

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.

lmo4103

12:49 pm on Sep 29, 2006 (gmt 0)

10+ Year Member



opelit,
your code in msg# 3101428 above [webmasterworld.com] works fine on my system! It works along with the login.php page in your first post [webmasterworld.com] and works for me! I just copy and pasted it and it worked. hmmm?

lmo4103

2:00 pm on Sep 29, 2006 (gmt 0)

10+ Year Member



Your sample1.php/welcome.php code also works for me -- I just copy and pasted.

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?

opelit

12:46 pm on Oct 3, 2006 (gmt 0)

10+ Year Member




Hi!
Sorry for late reply. I have tried a few codes on the system which are working fine. I tried one database connectivity code with MySql and working fine. But the trouble comes when i try out the code mentioned in last post.

So concluding PHP as the most complicated among all other scripting languages!

Thanks for your reply.
milind

lmo4103

1:08 pm on Oct 3, 2006 (gmt 0)

10+ Year Member



Create a file helloworld.php and put it in the htdocs directory with this code:

<?php
phpinfo();
?>

It produces output right?