views:

17

answers:

1

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");
?>
+3  A: 

$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.

Wrikken
i did turn on the display errors, but somehow it isn't showing anything, just a blank page. anyway, i corrected those errors, yet it displaying nothing except a blank page.
fuz3d
You cannot enable the showing of parse-error in a script itself. It should go either in php.ini or .htaccess, because on a parse error nothing in your script will be handled, including the setting to change `display_errors`. The next errors is that `$xmldoc->createElement('title xml:lang="ar"');` causes an uncaught exception because it is an illegal tagname (use ->setAtttribute for attributes). See our problem: you should **fix** the displaying of errors before continuing on this route, we are not your syntax/lint checkers.
Wrikken
ok, thanks. i checked the error log. before i corrected title-ar error the error was `[Thu Jul 29 21:45:37 2010] [error] [client 127.0.0.1] PHP Parse error: syntax error, unexpected '=' in [folder]/insert.php on line 13, referer: http://localhost/index.php`. after i corrected it, the error is `[Thu Jul 29 21:56:33 2010] [error] [client 127.0.0.1] PHP Parse error: syntax error, unexpected '=' in [folder]\\insert.php on line 15, referer: http://localhost/index.php` line 15 is `$title_ar = $_POST["title_ar"];`. i cannot figure out what else is wrong with this line.
fuz3d
Check the line before; sometimes PHP issues errors for the subsequent line when you're missing something like a semicolon.
Spoom
Wrikken
@spoom, i checked the code before and after, nothing seems to be wrong apparently.@wrikken, yes i changed all `-` to `_`.i've updated the code with the corrections. please check.
fuz3d
thanks @spoom @wrikken. the mistake was so silly. there was an extra comment tag.
fuz3d