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 10-09-2003, 10:51 PM   #1 (permalink)
CaN Opener
^ reads books
 
CaN Opener's Avatar
 
Join Date: Feb 2003
Location: San Fran
Posts: 66
CaN Opener is on a distinguished road
help im a noob

i picked up a book on php and this what it told me to do

this code is from test.html
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="handleform.php" method="post">
first name 
  <input type=text name="firstname" size=20><br>

last name <input type=text name="lastname" size=40> <br>
e-mail adress <input type=text name="email" size =60> <br>
comments <textarea name="comments" rows=5 cols=40></textarea><br>
<input type=submit name="submit" value="submit!"></form>

</body>
</html>
this code is from handleform.php

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
print "your first name is $firstname .<br>\n";
print "your last name is $lastname .<br>\n";
print "your email name is $email .<br>\n";
print "this is what u had to say: <br>\n $comments <br>\n";
?>
</body>
</html>
when i run the code i get these error messages

Quote:
Notice: Undefined variable: firstname in C:\Documents and Settings\can opener\Desktop\cantheham\handleform.php on line 10
your first name is .

Notice: Undefined variable: lastname in C:\Documents and Settings\can opener\Desktop\cantheham\handleform.php on line 11
your last name is .

Notice: Undefined variable: email in C:\Documents and Settings\can opener\Desktop\cantheham\handleform.php on line 12
your email name is .

Notice: Undefined variable: comments in C:\Documents and Settings\can opener\Desktop\cantheham\handleform.php on line 13
this is what u had to say:

ok i have several questions.
First my book says that in PHP u dont need to decalar vars like you do in "c" its says that its declared as soon as it is used so how can it be undeclared?

Second why would my book say to use print instead of echo as ive seen everywhere else any advantages to either one or disavantages?

Third why would the error messages show the local directory if this script is run on a server? shouldnt it show teh vir dir path?

fourth why dosent my code work any thoughts?


thank you for your time

can
__________________
there's no place like 127.0.0.1
CaN Opener is offline   Reply With Quote
Old 10-09-2003, 11:05 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
you are having a common problem regarding php error reporting.

there are 3 types of reporting: notices, warnings, and errors

the default php install reports notices, however it didn't used to which is why these instructions are probably left out of a lot of books.

warning and errors are things you do want reported .. however notices are not needed.

you can go to your php.ini file and find the line that says: error_reporting. make it look like this:
Code:
error_reporting  = E_ALL & ~(E_NOTICE | E_USER_NOTICE) ; display all errors and warnings
remember to restart your web server after you make the changes.

that should take care of those notices.

let us know how it works.
__________________
Mike
sde is offline   Reply With Quote
Old 10-10-2003, 01:40 AM   #3 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
your code looks fine. the problem is with your php configuration.

first, print and echo do exactly the same thing. use whichever one you like. 'print' is there for compatibility with perl, i believe.

you can do what sde said regarding the notices. however, that will not fix your main problem (that is, the variables are not defined). what's most likely going on is that your php configuration is set not to register variables submitted through forms as global variables by default. this page (http://www.php.net/register_globals) will explain the situation. and like sde said, this is a recent change and probably not in your php book.

if you don't want to change your server configuration, try using the _POST array instead. example:

PHP Code:
print "your first name is ".$_POST["firstname"]." .<br>\n"
joe_bruin is offline   Reply With Quote
Old 10-10-2003, 09:07 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
just make the changes in your php.ini file. especially if you are n00b to php. it will make life much easier for you as you explore that book.

otherwise most of the examples in your book will not work.

php.ini
Code:
error_reporting  = E_ALL & ~(E_NOTICE | E_USER_NOTICE)
register_globals on
__________________
Mike
sde is offline   Reply With Quote
Old 10-10-2003, 04:15 PM   #5 (permalink)
CaN Opener
^ reads books
 
CaN Opener's Avatar
 
Join Date: Feb 2003
Location: San Fran
Posts: 66
CaN Opener is on a distinguished road
:rock: koo ty i edited the php.ini and it works great now.
__________________
there's no place like 127.0.0.1
CaN Opener 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
true noob Odoggy5 PHP 5 08-22-2003 01:46 PM


All times are GMT -8. The time now is 08:02 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





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