p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Beginning PHP (http://p2p.wrox.com/forumdisplay.php?f=95)
-   -   Undefined Variable (http://p2p.wrox.com/showthread.php?t=45108)

aspire July 11th, 2006 05:39 PM

Undefined Variable
 
Right, I've got one of the PHP for Pro books from Wrox and im just beginning out and I've been trying to follow the tutorials but for some reason, this error keeps coming up even though i've followed the tutorials exactly. :/

Scenario: Userform.html has a form which ya put yer name in, it posts it to a processform.php but the processform.php always comes up with this error:
"Notice: Undefined variable: name in d:\Inetpub\wwwroot\testing\processform.php on line 4"

I understand that it doesnt seem to be getting the variable that I just inputted from the page before.

#### Userform.html

<html>

<FORM ACTION="processform.php" METHOD=POST>
Please type your name here: <br>
<INPUT TYPE=TEXT NAME=username> <br><br>
<INPUT TYPE=SUBMIT VALUE="Submit Data">
</FORM>
</html>

#### Processform.php

<html>

<?php
echo ("Welcome, " . $username . "!");
?>
</html>


Feedback please :)

i ASPIRE to be something....

Dj Kat July 11th, 2006 05:51 PM

You'll have to retrieve the variable $username first
Code:

<?
$username=$_POST["username"];
?>

__________________________________________________ ________
This is my junk I'm gona eat it

aspire July 11th, 2006 06:02 PM

Woah dude, ta for the quick reply, that script is in the "processform.php" page isnt it?
Aha, done it, awesome m8 :)

i ASPIRE to be something....

aspire July 11th, 2006 06:17 PM

Now I've encountered 1 more problem, I cant seem to keep the information from more than one page ago. Basicly its an error that says "Notice: Undefined index" :/

---------------------
You cant be something, until you aspire ;)

Dj Kat July 12th, 2006 07:00 AM

That's not correct.

When it doesn't get a value you get an error
this is what you need to do
<?
if(isset($_POST["username"])){
  $username=$_POST["username"];
}
else{
  echo("no value posted");
}
?>

__________________________________________________ ________
This is my junk I'm gona eat it


All times are GMT -4. The time now is 12:05 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.