Jump to content

Recommended Posts

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]

Link to comment
https://forums.phpfreaks.com/topic/78205-php-to-xml/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/78205-php-to-xml/#findComment-395753
Share on other sites

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"?>

Link to comment
https://forums.phpfreaks.com/topic/78205-php-to-xml/#findComment-395758
Share on other sites

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]

Link to comment
https://forums.phpfreaks.com/topic/78205-php-to-xml/#findComment-395768
Share on other sites

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/78205-php-to-xml/#findComment-395786
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.