PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1848
Number of posts: 5016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Undefined variable Posted by salted on 31 Aug 2002 at 1:21 PM
I just installed php 4 on apache 2 but I cant get this example to run. It gives the error
Notice: Undefined variable: frmName in c:\program files\apache group\apache\htdocs\test.php on line 4
Here's my code (test.php) I have no idea what could be wrong. Someone suggested looking at a config file but I dont know what to do with that.

<html>

<?php
if(!$frmName)
{

// Switch to HTML mode to display form
?>
<form action="test.php" method="post">
Name:
<input type="text" name="frmName" size="24">
<input type="submit" value="Submit">
<?php
}else{
?>
Hello <?php echo($frmName); ?>
!
<?php
}
?>

</html>

Report
Re: Undefined variable Posted by PrzemekG_ on 1 Sept 2002 at 6:42 AM
Try this:
: <html> 
: 
: <?php 
: if(!isset($frmName))
: { 
: 
: // Switch to HTML mode to display form 
: ?> 
: <form action="test.php" method="post"> 
: Name: 
: <input type="text" name="frmName" size="24"> 
: <input type="submit" value="Submit"> 
: <?php 
: }else{ 
: ?> 
: Hello <?php echo($frmName); ?> 
: ! 
: <?php 
: } 
: ?> 
: 
: </html> 

Report
Re: Undefined variable Posted by salted on 1 Sept 2002 at 3:44 PM
: Try this:
:
: : <html> 
: : 
: : <?php 
: : if(!isset($frmName))
: : { 
: : 
: : // Switch to HTML mode to display form 
: : ?> 
: : <form action="test.php" method="post"> 
: : Name: 
: : <input type="text" name="frmName" size="24"> 
: : <input type="submit" value="Submit"> 
: : <?php 
: : }else{ 
: : ?> 
: : Hello <?php echo($frmName); ?> 
: : ! 
: : <?php 
: : } 
: : ?> 
: : 
: : </html> 
: 

:

that doesnt work either... still gives me the original error message

Report
Re: Undefined variable Posted by Mark Strijbos on 1 Sept 2002 at 11:15 PM
: : Try this:
: :
: : : <html> 
: : : 
: : : <?php 
: : : if(!empty($frmName))
: : : { 
: : : 
: : : // Switch to HTML mode to display form 
: : : ?> 
: : : <form action="test.php" method="post"> 
: : : Name: 
: : : <input type="text" name="frmName" size="24"> 
: : : <input type="submit" value="Submit"> 
: : : <?php 
: : : }else{ 
: : : ?> 
: : : Hello <?php echo($frmName); ?> 
: : : ! 
: : : <?php 
: : : } 
: : : ?> 
: : : 
: : : </html> 
: : 

: :


Report
Re: Undefined variable Posted by salted on 2 Sept 2002 at 9:13 AM
That isnt working either.... It still isnt automatically making a variables from the post... I still get the error Notice: Undefined variable: frmName in c:\program files\apache group\apache\htdocs\test.php on line 16

Report
Re: Undefined variable Posted by Mark Strijbos on 2 Sept 2002 at 11:21 PM
: That isnt working either.... It still isnt automatically making a variables from the post... I still get the error Notice: Undefined variable: frmName in c:\program files\apache group\apache\htdocs\test.php on line 16

oops! my mistake... here is a small correction:

<html> 
<?php 
if( empty($frmName) ) // drop the '!'
{ 
// Switch to HTML mode to display form 

Report
Re: Undefined variable Posted by salted on 3 Sept 2002 at 3:00 PM
I guess I should make this more clear. Any line with the variable name no matter what I do with the variable still gives the same error. I know its not my code cause I can run it at a computer at work... it just that the php I installed is not working properly and I was hoping someone knew what to do with it.
Report
Re: Undefined variable Posted by Mark Strijbos on 3 Sept 2002 at 11:28 PM
: it just that the php I installed is not working properly

highly unlikely!
you are getting a PHP error message ergo: PHP is indeed working and trying to run the script. please look again at my previous reply and try the suggested correction.





Report
Re: Undefined variable Posted by salted on 4 Sept 2002 at 1:19 PM
well I ran your stuff when you first posted it... and I get the same errors.
Report
Re: Undefined variable Posted by salted on 4 Sept 2002 at 2:40 PM
: well I ran your stuff when you first posted it... and I get the same errors.
:
Only I get it for line 16 instead of 5
Report
Re: Undefined variable Posted by salted on 4 Sept 2002 at 4:40 PM
I just thought I'd let you know I found out what is wrong. The new version of php 4 has a security bug in it and there is a fix for it. Thats why my script wasnt running... Thanks though.
Report
Re: Undefined variable Posted by bencoco on 11 Sept 2002 at 1:34 PM
I have the same problem with my php program...
Unfortunatly, I can't find a Win32 fix.
I have the php 4.2.1 version.

Do you have any URL ?

Regards,

Eric
Report
Re: Undefined variable Posted by releasedj on 6 Sept 2002 at 5:11 AM
This isn't the source of your problem.

If you just downloaded PHP, I'm presuming that you downloades 4.1 or greater.

If so, by default, all variables passed to the php script by POST, GET, COOKIE, SESSION ..etc are not automatically made available in the global scope.

To access your variable "$frmName" you must use "$_POST['frmName']".
If you have a script with lots of variables referencing POST or GET variables in the same way you can use
import_request_variables('GPC');
.. this will import all Get, Post and Cookie variables into the global scope.

I hope this helps.

Kelvin
Report
Re: Undefined variable Posted by Naug on 8 Sept 2002 at 6:23 AM
I got similar prob... to test I just made

<?php
print"$n";
?>

I get Notice: Undefined variable: n in /home/s00503/.www/test.php on line 2

Also php 4 installed couple of weeks ago.... So I was wandering maybe this has to do with default settings? Anyone know?
Report
Re: Undefined variable Posted by Mark Strijbos on 9 Sept 2002 at 3:56 AM
: I got similar prob... to test I just made
:
: <?php
: print"$n";
: ?>
:
: I get Notice: Undefined variable: n in /home/s00503/.www/test.php on line 2

well, perhaps you should take a look at your error reporting level. looks like you're running in "debug mode" as you get notices & warnings for anything that is a potential (!) problem. In other words: this is not a error report, it is a "Notice"; a warning because in general it is not a good idea to use undefined variables



Report
Re: Undefined variable Posted by Naug on 11 Sept 2002 at 1:57 AM
Yep ty it stood at 2047, I lowered it to 7 so it seems to work now... Is there a standart "recomended" level for this?
:
: well, perhaps you should take a look at your error reporting level. looks like you're running in "debug mode" as you get notices & warnings for anything that is a potential (!) problem. In other words: this is not a error report, it is a "Notice"; a warning because in general it is not a good idea to use undefined variables
:
:
:
:

Report
Re: Undefined variable Posted by Mark Strijbos on 11 Sept 2002 at 3:57 AM
There are 4 types of errors and warnings in PHP. They are:
1 - Normal Function Errors
2 - Normal Warnings
4 - Parser Errors
8 - Notices (warnings you can ignore)

IMHO you should set the level to 15 during development and to 1 in production environments



Report
Re: Undefined variable Posted by Naug on 11 Sept 2002 at 5:46 AM
value constant
1 E_ERROR
2 E_WARNING
4 E_PARSE
8 E_NOTICE
16 E_CORE_ERROR
32 E_CORE_WARNING
64 E_COMPILE_ERROR
128 E_COMPILE_WARNING
256 E_USER_ERROR
512 E_USER_WARNING
1024 E_USER_NOTICE
2047 E_ALL

I never saw core error or compile error etc are they something to worry about?


: There are 4 types of errors and warnings in PHP. They are:
: 1 - Normal Function Errors
: 2 - Normal Warnings
: 4 - Parser Errors
: 8 - Notices (warnings you can ignore)
:
: IMHO you should set the level to 15 during development and to 1 in production environments
:
:
:
:

Report
Re: Undefined variable Posted by KyllerJ on 2 Oct 2002 at 9:36 AM
Seems like I'm having similar problems in some of my scripts. Could you please show how to lower the error reporting level so php will not report undefined variable notices?

Thanks
Report
Re: Undefined variable Posted by hico on 20 Sept 2002 at 4:50 AM
: I just installed php 4 on apache 2 but I cant get this example to run. It gives the error
: Notice: Undefined variable: frmName in c:\program files\apache group\apache\htdocs\test.php on line 4
: Here's my code (test.php) I have no idea what could be wrong. Someone suggested looking at a config file but I dont know what to do with that.
:
: <html>
:
: <?php
: if(!$frmName)
: {
:
: // Switch to HTML mode to display form
: ?>
: <form action="test.php" method="post">
: Name:
: <input type="text" name="frmName" size="24">
: <input type="submit" value="Submit">
: <?php
: }else{
: ?>
: Hello <?php echo($frmName); ?>
: !
: <?php
: }
: ?>
:
: </html>
:
:

It should be something like this:

if (isset($_POST['frmName']))

But I still don't see the purpose or what you want to achieve with this code? You want the user to enter his/her name and then click the Submit button, right? And then display his/her name. Am I correct?



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.