简体   繁体   中英

inserting to xml displays a blank page

i'm trying to insert data into xml using php domdocument. however when i hit enter, it just displays a blank page showing no error. what am i doing wrong?

UPDATED:

   <?php 

error_reporting(E_ALL);
ini_set("display_errors", 1);


    $xmldoc = new DOMDocument();
    if(file_exists('test.xml')){
    $xmldoc->load('test.xml');
    } else {
    $xmldoc->loadXML('<root/>');
    }

    /*get the values of the html: */
    $title_ar = $_POST["title_ar"];
    $title_en = $_POST["title_en"];

    $intro = $_POST["intro"];

    $v_ar = $_POST["v_ar"];
    $v_en = $_POST["v_en"];
    $v_tren = $_POST["v_tren"];

    /*get the values of the html: */

    $root = $xmldoc->firstChild;

    if ($xmldoc->getElementsByTagName("title")->length == 0) {
    /* Arabic */
    $el_title_ar = $xmldoc->createElement('title'); 
    $root->appendChild($el_title_ar);

    $text_title_ar = $xmldoc->createTextNode($title_ar);
    $el_title_ar->appendChild($text_title_ar);
    /* Arabic */

    /* English */
    $el_title_en = $xmldoc->createElement('title'); 
    $root->appendChild($el_title_en);

    $text_title_en = $xmldoc->createTextNode($title_en);
    $el_title_en->appendChild($text_title_en);
    /* English */
    }
    else if ($xmldoc->getElementsByTagName("introduction")->length == 0) {
    $el_intro = $xmldoc->createElement('introduction'); 
    $root->appendChild($el_intro);

    $el_intro_para = $xmldoc->createElement('para'); 
    $el_intro->appendChild($el_intro_para);

    $text_intro = $xmldoc->createTextNode($intro);
    $el_intro_para->appendChild($text_intro);
    }

    $verse = $xmldoc->createElement('verse');
    $root->appendChild($verse);


    /* Arabic */
    $verse_p = $xmldoc->createElement('p');
    $verse->appendChild($verse_p);

    $v_ar_p = $xmldoc->createTextNode($v_ar);
    $verse_p->appendChild($v_ar_p);
    /* Arabic */


    /* English Translation*/
    $verse_trans = $xmldoc->createElement('trla');
    $verse->appendChild($verse_trans);

    $v_en_trans = $xmldoc->createTextNode($v_en);
    $verse_trans->appendChild($v_en_trans);
    /* English Translation*/


    /* English Transliteration*/*/
    $verse_translit = $xmldoc->createElement('trli');
    $verse->appendChild($verse_translit);

    $v_en_translit = $xmldoc->createTextNode($v_tren);
    $verse_translit->appendChild($v_en_translit);
    /* English  Transliteration*/

    /*Save the XML File*/
    $xml->formatOutput = true; 
    $xmldoc->save('test.xml');

    header("Location: index.php");
?>

$title-ar is an illegal variable name. It would mean 'the variable $title minus the constant ar , which would make it an expression, and you cannot assign ( = ) anything to an expression. You would do well to turn on display_errors while developing, it would have told you about the parse error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM