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.