geraldinecmc Posted November 21, 2007 Share Posted November 21, 2007 Hello all, I'm completely new to php. Ok there is my goal : I wish to have a form with a text box that allows me to change an xml document. What I have done so far (with the help of books and nice advises) is : - One "admin" folder with an html file (edit_xml.html) and a php file (verif_xml.php). - One xml folder "dossier_xml" with an xml file (fichier_xml.xml). The codes are the following : EDIT_XML.HTML : // <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Document sans nom</title> </head> <body> <table><tr><td> <form method="post" action="verif_xml.php"><!--nous allons envoyer les données par post a verif_xml.php--> <textarea name="donnees"></textarea> <input type="submit"> </form> </td></tr></table> </body> </html> // VERIF_XML.PHP //<?php $texte = addslashes(htmlspecialchars($_POST['donnees'])); $xml =' <?xml version="1.0" encoding="ISO-8859-1"?> <balise truc="machin"> <texte>'.$texte.'</texte> </balise>'; $dossier = '../dossier_xml/'; $fichier = 'fichier_xml.xml'; $dir = opendir($dossier) or die('Impossible d\'ouvrir le dossier'); $chemin = fopen($dossier, $fichier, 'w'); fwrite($chemin, "$xml"); ?> // When I test the form, and press "submit", it send me back on the screen the php file content and does not change the xml file. What am I doing wrong? Can somebody help me? Thank you! [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/78205-php-to-xml/ Share on other sites More sharing options...
~n[EO]n~ Posted November 21, 2007 Share Posted November 21, 2007 When I test the form, and press "submit", it send me back on the screen the php file content and does not change the xml file. What am I doing wrong? Can somebody help me? It is working man... When I tested your code it wrote <?xml version="1.0" encoding="ISO-8859-1"?> <balise truc="machin"> <texte>hello there </texte> </balise> in XML file Quote Link to comment https://forums.phpfreaks.com/topic/78205-php-to-xml/#findComment-395753 Share on other sites More sharing options...
geraldinecmc Posted November 21, 2007 Author Share Posted November 21, 2007 Well..Ican't figure it out.. I just tried again, but nothing is written! Did you use the exact code I sent? Quote Link to comment https://forums.phpfreaks.com/topic/78205-php-to-xml/#findComment-395756 Share on other sites More sharing options...
~n[EO]n~ Posted November 21, 2007 Share Posted November 21, 2007 I removed the directory line in PHP file cause all files were in same folder edit_xml.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Document sans nom</title> </head> <body> <table><tr><td> <form method="post" action="verify_xml.php"><!--nous allons envoyer les données par post a verif_xml.php--> <textarea name="donnees"></textarea> <input type="submit"> </form> </td></tr></table> </body> </html> verify_xml.php <?php $texte = addslashes(htmlspecialchars($_POST['donnees'])); $xml =' <?xml version="1.0" encoding="ISO-8859-1"?> <balise truc="machin"> <texte>'.$texte.'</texte> </balise>'; //$dossier = ''; $fichier = 'dossier_xml.xml'; // i comment the directory and this line below cause I had the XML file in the same folder too.. //$dir = opendir($dossier) or die('Impossible d\'ouvrir le dossier'); $chemin = fopen($fichier, 'w'); fwrite($chemin, "$xml"); echo "done"; ?> dossier_xml.xml This page had only this line at first and when I added from browser the data got added through PHP <?xml version="1.0" encoding="ISO-8859-1"?> Quote Link to comment https://forums.phpfreaks.com/topic/78205-php-to-xml/#findComment-395758 Share on other sites More sharing options...
geraldinecmc Posted November 21, 2007 Author Share Posted November 21, 2007 Hello again... Thank you for your help... So there is in attachement my last working folder including your changes (maybe the problem was coming from the path). And the bad news is that it is still not working, offline or online. When it's online, the path is "http://www.mywebsite.com/admin/edit_xml/html" I have no clue. Just read again and again to see if there were no typing mistake problems but nothing... Am I completely stupid or what? [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/78205-php-to-xml/#findComment-395768 Share on other sites More sharing options...
~n[EO]n~ Posted November 21, 2007 Share Posted November 21, 2007 Do you get any error or ? I think you are using MAC, your files don't work for me ??? Quote Link to comment https://forums.phpfreaks.com/topic/78205-php-to-xml/#findComment-395774 Share on other sites More sharing options...
geraldinecmc Posted November 21, 2007 Author Share Posted November 21, 2007 Yes..I'm using MAC... no I get the "done" back comment that the task has been executed but when I take a look at the xml file, nothing has changed.. Quote Link to comment https://forums.phpfreaks.com/topic/78205-php-to-xml/#findComment-395779 Share on other sites More sharing options...
geraldinecmc Posted November 21, 2007 Author Share Posted November 21, 2007 Is it the whole zip file that you can't open, or just one file? Maybe I can do something Quote Link to comment https://forums.phpfreaks.com/topic/78205-php-to-xml/#findComment-395780 Share on other sites More sharing options...
~n[EO]n~ Posted November 21, 2007 Share Posted November 21, 2007 Zip files get uncompressed and when I open the file I get some characters (like box), I am using XP so I think your file won't open. Now keep this in top of your PHP file, if there are any errors it will show. error_reporting(E_ALL); and try once keeping file_put_contents instead of fwrite I think there must be some setting in php.ini file which must be modified for your code to work correctly. I don't know about MAC, maybe someone will help you out. Quote Link to comment https://forums.phpfreaks.com/topic/78205-php-to-xml/#findComment-395786 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.