PHP Global variable in class is reset

Posted by Robert on Stack Overflow See other posts from Stack Overflow or by Robert
Published on 2010-04-08T15:03:09Z Indexed on 2010/04/08 15:23 UTC
Read the original article Hit count: 192

Filed under:
|
|

I have a web form that manipulates records in a MySQL database. I have a method for displaying an edit interface for both creating new records and editing them

if ($_POST['new_page']) {
        print "<h2>Create new page</h2>\n";
        $isNew=1;
        $this->EditForm();
    } else if($_POST['edit']){
        print "<h2>Edit page</h2>\n";
        $isNew=0;
        $this->EditForm();
    }

I am trying to use the global variable $isNew to determine where a record is to be added or updated. However, whenever my SaveChanges() function is run, $isNew is always 0. $isNew is declared immediately after the class declaration, outside all of the functions.

class Editor{
    public $isNew;

© Stack Overflow or respective owner

Related posts about php

Related posts about global