PHP & HTML forms - Pl help resolve basic problem

Status
Not open for further replies.

tuxfan

Technomancer
I am getting an error in PHP. What's wrong? Its on Win98SE, Apache 2.0.54, PHP 5.

Here's forms.htm file
Code:
<html>
<head></head>
<body>
  <form action="forms.php" method="GET">
    <input type="text" name="user">

    <textarea name="address" rows="5" cols="40"></textarea>

    <input type="submit" value="Submit">
  </form>
</body>
</html>

Here's the forms.php file
Code:
<html><head></head>
<body>
  <?php
    print "Welcome [b]$user[/b]
";
    print "Your address is:[b]$address[/b]";
  ?>
</body>
</html>

Here's the error that I get :( The URL of the browser window is *localhost/forms.php?user=tuxfan&address=Mumbai
Notice: Undefined variable: user in D:\apacheww\forms.php on line 4
Welcome

Notice: Undefined variable: address in D:\apacheww\forms.php on line 5
Your address is:
 

kalpik

In Pursuit of "Happyness"
Hi!

Try this:
Code:
<html><head></head>
<body>
  <?php
    $user=$_GET['user'];
    $address=$_GET['address'];
    print "Welcome [b]$user[/b]
";
    print "Your address is:[b]$address[/b]";
  ?>
</body>
</html>

Hehe, if im not wrong, i was the one who got u started wid PHP (if u remember that is ;))

One suggestion: Go through the documentation at *www.php.net You will find everything related to PHP there.

No book is better than that!
 

kalpik

In Pursuit of "Happyness"
Another solution. You dont need another html file for this!

Code:
<html><head></head>
<body>
  <?php
    $submit=$_GET['submit'];
    if(isset($submit))
    {
         $user=$_GET['user'];
         $address=$_GET['address'];
         print "Welcome [b]$user[/b]
";
         print "Your address is:[b]$address[/b]";
    }
    else
    {
           ?>
           <form action="forms.php" method="GET">
              <input type="text" name="user">

              <textarea name="address" rows="5" cols="40"></textarea>

              <input type="submit" value="Submit">
           </form> 
           <?php
    }
  ?>
</body>
</html>

Havent tested it, maybe a typo here n there! :p
 
OP
tuxfan

tuxfan

Technomancer
hey kalpik, thanks :D It worked. I would have PMed you if I wouldn't have got my answer in 24 hours ;) I know you gave the last push required for me to get started on PHP.

I can understand what you are doing in the new forms.php file. The forum submission and processing is happenning in the same file depending on whether the submit button has called the page or its just loaded in the borwser through a link (or directly). Thanks for the tip :D

Actually, I have copied and pasted the code from an e-book. It gave errors. I checked another e-book, syntax looked right. I opened PHP manual, syntax still looked right :roll: So I was stumped. I even tried $_GET but it didn't work, may be I used $GET and missed out the underscore. :oops:

BTW, I am enjoying PHP :D
 

kalpik

In Pursuit of "Happyness"
Sure anytime buddy! PHP really IS amazing.
Im actually doing training in TATA Infotech nowdays. Working on some JSP project, so got a chance to learn JSP too. But believe me JSP is NOTHING compared to PHP!

And u guessed right about what im doing in the new forms.php. I knew u were smart enough to figure that out urself, thats why didnt explain ;)

And once again im saying that nothing beats the original PHP Manual from *php.net. I've downloaded the many HTML files version. It is updated most frequently.

And if any other help required, ill be more than glad to help (if i can help that is!). Hehe...

Take care!
 
S

sunnydiv

Guest
hey tuxfan u r using a crappy server

use apache with XAMPP ur first script works fine
 

kalpik

In Pursuit of "Happyness"
But that is not how the standards go! If u are learning something, learn it according to standards. Good programming practice is also an important thing.

And how dare u call Apache a crappy server!? Hehe its the most popular server on the internet!
 
S

sunnydiv

Guest
m not calling apache the crappy one, even i use it, i am callin it a crappy package
 

kalpik

In Pursuit of "Happyness"
Oh! You talking about PHP+Apache+MySQL packages?
Well IMO, manual installation is the best, and i think Tuxfan did that only! Lol...
 
OP
tuxfan

tuxfan

Technomancer
Yes kalpik you are right. I did manual installtion. I used (and have saved) that thread in Tutorials section where Deep posted the details and you fine tuned them. :) Thanks so much for your help.

I will surely get in touch with you as and when I am stuck. I now have a reliable source for all PHP difficulties. I will not lose that source so easily ;) :lol:

sunnydiv, try out the manual installtion. Its not difficult at all!! Refer to that thread in Tutorials. Deep and kaplik have really made it easy. I did it in first shot!! So can you :)

I have always preferred some control over what I am doing and don't rely on automation too much. Nothing is ever automatic!! Someone has done it for you and therefore it looks automatic. Why not find out how he has done it? ;)

Necessity is the mother of invention
Inquisitiveness is the mother of knowledge about that invention ;) :D
 
Status
Not open for further replies.
Top Bottom