Undefined variable

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 filesapache groupapachehtdocs est.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.



<?php
if(!$frmName)
{

// Switch to HTML mode to display form
?>

Name:


<?php
}else{
?>
Hello <?php echo($frmName); ?>
!
<?php
}
?>



«1

Comments

  • Try this:
    [code]
    :
    :
    : <?php
    : [red]if(![b]isset($frmName)[/b])[/red]
    : {
    :
    : // Switch to HTML mode to display form
    : ?>
    :
    : Name:
    :
    :
    : <?php
    : }else{
    : ?>
    : Hello <?php echo($frmName); ?>
    : !
    : <?php
    : }
    : ?>
    :
    :
    [/code]
  • : Try this:
    : [code]
    : :
    : :
    : : <?php
    : : [red]if(![b]isset($frmName)[/b])[/red]
    : : {
    : :
    : : // Switch to HTML mode to display form
    : : ?>
    : :
    : : Name:
    : :
    : :
    : : <?php
    : : }else{
    : : ?>
    : : Hello <?php echo($frmName); ?>
    : : !
    : : <?php
    : : }
    : : ?>
    : :
    : :
    : [/code]
    :

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

  • : : Try this:
    : : [code]
    : : :
    : : :
    : : : <?php
    : : : [red]if(![b]empty($frmName)[/b])[/red]
    : : : {
    : : :
    : : : // Switch to HTML mode to display form
    : : : ?>
    : : :
    : : : Name:
    : : :
    : : :
    : : : <?php
    : : : }else{
    : : : ?>
    : : : Hello <?php echo($frmName); ?>
    : : : !
    : : : <?php
    : : : }
    : : : ?>
    : : :
    : : :
    : : [/code]
    : :


  • 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 filesapache groupapachehtdocs est.php on line 16

  • : 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 filesapache groupapachehtdocs est.php on line 16

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

    [code]

    <?php
    [red]if( empty($frmName) ) // drop the '!'[/red]
    {
    // Switch to HTML mode to display form
    [/code]
  • 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.
  • : 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.





  • well I ran your stuff when you first posted it... and I get the same errors.
  • : 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
  • 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.
  • 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
  • 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?
  • : 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



  • 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
    :
    :
    :
    :

  • 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



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories