Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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....
Reply With Quote
  #2 (permalink)  
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
Reply With Quote
  #3 (permalink)  
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....
Reply With Quote
  #4 (permalink)  
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 ;)
Reply With Quote
  #5 (permalink)  
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:32 AM.


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