Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php help please for variables

Status
Not open for further replies.

AbbasAkhtar

Programmer
Dec 16, 2002
25
GB
Hello, I need some help with php, this is what I'm trying to do is pass on variables/parameters from one html page to another, it really is important, I'll explain my problem near the end, this is my system configuration.

Windows Millenium Edition

My online digitalamt.co.uk server is apache, so I have downloaded and set up apache on my laptop, which is version 2.0.4.5. (I've tried 1.3.5 too, but the same thing happens)

I have installed MySQL 3.21.# (but I am not concerned with this just now).

I also have installed PHP 4.

OK this is what I am trying to do, I have put all my files in the htdocs folder, I have 2 files, one called index.html and the other called information.php.

This is what happens, in the index.html, it contains 2 text boxes, and a submit button, what is supposed to happen is that the information.php file is supposed to receive the variables/parameters so it can display it on the other page. This is the code I am using for both files.


*********************index.html*****************************

<html>
<head>
<title>My Form</title>
</head>
<body>

<form action=&quot;information.php&quot; method=post>

My name is:
<br> <input type=&quot;text&quot; name=&quot;nam&quot;>

<p>
My age is:
<br> <input type=&quot;text&quot; name=&quot;age&quot;>
<p>

<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Enter my Data!&quot;>
</form>

</body>
</html>

**************end of index.html***************************



************************information.php********************

<html>
<head>
<title>Information</title>
</head>
<body>
Hi <?php print $nam; ?>
<p>
You are <?php print $age; ?> years old.
<p>
Bye.
</body>
</html>
***************end of information.php**********************



The above two files which are in my htdocs, both load normally, but when I hit submit, this is what happens:

the page loads in ie, when I navigate to localhost or 127.0.0.1 the index.html loads perfectly, I input data,

I hit submit, on the next page (information.php) I receive this on the page:


**********************when information.php loads***********

Hi
Notice: Undefined variable: nam in C:\Program Files\Apache Group\Apache2\htdocs\information.php on line 6

You are
Notice: Undefined variable: age in C:\Program Files\Apache Group\Apache2\htdocs\information.php on line 8
years old.

Bye.
************************************************************

It works normally, if I use variables in a single html page, but if I try to pass them to other html files, it doesn't work. I have tried method=get and method=post none of them work. Is it something to do with my php.ini file in my windows directory. I am not really sure which ini setting I should edit, although I have had a look.

Any help would be appreciated, thanks. p.s. I don't have the apache monitor activated, I've tried it whilst activated and whilst shut down.

And I couldn't get this to work either:



******************index2.php******************

<html>
<head>
<title>Test PHP</title>
</head>
<body>
<?php
//just an experimental php script
print &quot;<p>The value is:&quot; + $username;

?>
<input type=&quot;text&quot; name=&quot;$username&quot; size=&quot;40&quot; maxlength=&quot;40&quot; value=&quot;hi&quot;>
<?php
//just an experimental php script
print &quot;<p>The value is:&quot; + $username;

?>
</body>
</html>

************************************************

also, I set up in apache the httpd.conf to run php files with php.exe in C:/php/ which is fine, although I did not try the cgi module, which is php4apache.dll which I can not find in the php folder, and I don't know where I can find it to install it, maybe I need this to make it work,

any help will be appreciated. thankyou. even if you could explain how you set up your apache and php. thanks.
 
At the top of your information.php page, you need to set the variables to the values of the post from the previous page:
<?php
$nam = $_POST['nam'];
$age = $_POST['age'];
?>
html>
<head>
<title>Information</title>
</head>
<body>
Hi <?php print $nam; ?>
<p>
You are <?php print $age; ?> years old.
<p>
Bye.
</body>
</html>

You need to read through a simple set up manual/web page for setting up Apache/PHP correctly.
Try this has some good try outs in.

sipps
 
yes., i have the funy thing is i used webmonkeys guide. but their tutorials, i folowed their tutorials for the above, well thanks ,i think ur idea will work, ill test it thanks man.
 
Sipps,
Do you have to set those variables on the information page? Aren't values of a post from the previous page accesable with just <?php print $_POST['nam']; ?> alone?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top