Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 11th, 2006, 05:39 PM
Registered User
 
Join Date: Jul 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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....
 
Old July 11th, 2006, 05:51 PM
Friend of Wrox
 
Join Date: Nov 2005
Location: Rotterdam, , Netherlands.
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You'll have to retrieve the variable $username first
Code:
<?
$username=$_POST["username"];
?>
__________________________________________________ ________
This is my junk I'm gona eat it
 
Old July 11th, 2006, 06:02 PM
Registered User
 
Join Date: Jul 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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....
 
Old July 11th, 2006, 06:17 PM
Registered User
 
Join Date: Jul 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 ;)
 
Old July 12th, 2006, 07:00 AM
Friend of Wrox
 
Join Date: Nov 2005
Location: Rotterdam, , Netherlands.
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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




Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined variable adel_88 BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 July 9th, 2007 03:21 PM
Undefined variable najib Beginning PHP 4 July 1st, 2005 08:12 AM
undefined variable !! cody44 Beginning PHP 3 January 20th, 2005 05:47 PM
Undefined Variable fpolan Beginning PHP 9 July 15th, 2004 06:24 AM
Undefined Variable Some Help! knight Beginning PHP 7 February 19th, 2004 07:07 AM





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