Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-18-2004, 02:00 AM   #1 (permalink)
DavH27
PHP Pilgrim
 
DavH27's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 170
DavH27 is on a distinguished road
[mfp] Inputting forms to output in PHP

Now these should be pretty simple, right? Grr then why isn't it working for me!!??

I have even copy/paste the example exactly from WebMonkey.com :

index.php
Code:
<form action="test.php" method=post> 

 My name is:
 <br> <input type="text" name="YourName"> 

 <p> My favorite dirty word is: 
 <br> <input type="text" name="FavoriteWord"> 
 <p>

 <input type="submit" name="submit" value="Enter My Data!">
 </form>
test.php
Code:
<p>
Hi <?php print $YourName; ?>

<p>
You like the word <b> <?php print $FavoriteWord; ?> !?! </b>

<p>You oughta be ashamed of yourself!
Look good yeah? Well it does to me anyway...but then I fill the form in. Click submit then I get hit with this:
Quote:
Hi
Notice: Undefined variable: YourName in C:\My Documents\phpTest\test.php on line 9


You like the word
Notice: Undefined variable: FavoriteWord in C:\My Documents\phpTest\test.php on line 12
!?!

You oughta be ashamed of yourself!
But I had defined the variables in the previous form, surely?
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
DavH27 is offline   Reply With Quote
Old 08-18-2004, 02:11 AM   #2 (permalink)
DavH27
PHP Pilgrim
 
DavH27's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 170
DavH27 is on a distinguished road
Ahh fixed it!

It seemed that the method that WebMonkey was teaching em was out of date or something...

I used a tutorial from uk.php.net
PHP Code:
<?php print $_POST['YourName']; ?>  //Used this instead of ...
<?php print "$YourName"?>   // <-- this
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
DavH27 is offline   Reply With Quote
Old 08-18-2004, 04:42 AM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
by default, php reports notices. it is good practice to define your variables, although pretty damn annoying for someone learning php because most php tutorials don't define variables. you will definately want to turn notice reporting off.

for example, even if you do this:
PHP Code:
<?
$i 
0;
?>
you will probably get a notice error because you didn't declare $i as a var. i know it probably doesn't seem like a big deal declaring every variable since you are coming from a vb background, but i'm sure 90% of the tutorials out there don't do it. there is really no need to do it with php.

register globals is another setting that is usually turned off. now this may be confusing, but it also relates to what you are talking about here. let's say you have notices turned off now. you will NOT get that error if you tried to print $YourName. but another thing you would notice is that NOTHING at all would print.

most web servers that you pay to host on has register globals turned on. this would allow you to get away with NOT using the $_POST or $_GET before any variable names you try to use that have been either submitted from a form or in the url. it is very good practice to use $_POST and $_GET for everything as i have learned in my experience so i always use them now.

so here is my recomendation. go to your php.ini file ( c:\windows\php.ini ) i think that's where it's at .. and change the error reporting line to the following:
Code:
error_reporting  =  E_ALL & ~E_NOTICE
i don't recommend it, but if you did want to turn register_global s on, do this
Code:
register_globals On
this may make following other tutorials easier for you for now.

once you make the changes, restart your web server.
__________________
Mike
sde is offline   Reply With Quote
Old 08-18-2004, 05:44 AM   #4 (permalink)
DavH27
PHP Pilgrim
 
DavH27's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 170
DavH27 is on a distinguished road
But surely when testing the php scripts that I write, I want to see what is not working as it should, the line number and other details in the error notice?

This makes debugging a walk in the park.

So why you telling me to turn it off?
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
DavH27 is offline   Reply With Quote
Old 08-18-2004, 06:14 AM   #5 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
Too much information can be a bad thing.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 08-18-2004, 06:24 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
php will report the following errors: warning, parse, notice, error

i'm telling you to only turn notice reporting off. if you make a parse error, or some other error that you will need to debug, it will still show you what line the error is on .. it just won't report notices.

i've never worked on a server that has had notice reporting turned on .. and most of the time, the only time php coders declare variables is when they are writting classes. ( object oriented php )

ultimately the choice is yours =) .. i'm just giving you advice to make life easier as you are new to php and will probably be using online tutorials. most tutorials will NOT declare their variables which will cause you to get notice errors.
__________________
Mike
sde is offline   Reply With Quote
Old 08-18-2004, 06:31 AM   #7 (permalink)
DavH27
PHP Pilgrim
 
DavH27's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 170
DavH27 is on a distinguished road
Problem is, online tutorials get out of date and that is a bugger for people like me.

Okay I'll turn em off
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
DavH27 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Comes of Age sde Code Newbie News 0 04-14-2004 11:41 AM
I need to learn PHP Nitro PHP 9 06-28-2003 11:24 AM


All times are GMT -8. The time now is 07:14 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting