Getting an non-object error in my php script

Posted by Disowned on Stack Overflow See other posts from Stack Overflow or by Disowned
Published on 2012-03-25T23:07:05Z Indexed on 2012/03/25 23:29 UTC
Read the original article Hit count: 229

Filed under:

Hey I was trying to call a script to made some changes to an html file, however when I run the script it tells me that it's making a call to a non-object. Obviously I did something wrong, but what? Here's the script.

    /*Dom controllers*/
    $dom = new DOMDocument();
    $dom->loadHTML('index.html');
    $id = $dom->getElementById('contact_us');
    $p = $dom->appendChild(new DOMElement('p'));
    $op = $dom->getElementsByTagName('p');

    /* Dem POST vars used by dat Ajax mah ziggen, yeah boi*/
    if (isset($_POST['Home']) && isset($_POST['About']) && isset($_POST['Contact']) && isset($_POST['sexyText'])){
    $home = $_POST['Home'];
    $about = $_POST['About'];
    $contact = $_POST['Contact'];
    $text = $_POST['sexyText'];
    trim($home);
    trim($about);
    trim($contact);
    trim($text);
    }

    function post(){
        global $dom, $id, $home, $about, $contact, $text, $textp, $p, $op;
                $textp = $dom->createTextNode($text);
                $p->appendChild($textp);
                $id->replaceChild($p, $op);
                $dom->saveHTMLFile('index.html');
    }


    post();
    echo 1;


?>

The error happens at the replaceChild function.

© Stack Overflow or respective owner

Related posts about php