using simplexml with php and html

I am trying to get a select to change a xml file here is the codes.


the doc.xml file
<?xml version="1.0"?>

<showimage_1>yes</showimage_1>

Open in new window



THis is the php code

<?php

$file = $_SESSION['docroot_path']."doc.xml";

$xml = simplexml_load_file($file);


if($_SERVER['REQUEST_METHOD'] == 'POST')

{

$chshowimage_1 = isset($_POST["showimage_1"]) ? stripslashes($_POST["showimage_1"]) : '';

if ($chshowimage_1 =="") {	
		}
		else {
				$xml->showimage_1 = $chshowimage_1;
				$xml->asXML($file);
		}
}

else

{
	}
?>

Open in new window


This is the form code

<form name="changestuffform" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">

<select id="showimage_1" name="showimage_1">

              <option value="yes" selected>Yes</option>

              <option value="no">No</option>

<option value="maybe">maybe</option>

</select>

<input type="submit" value="Save &gt;&gt;">



</form>

<script type="text/javascript">
document.getElementById("topspacing").value = '<? echo $xml->showimage_1 ?>';
</script>   

Open in new window



This doesn't change the doc.xml file
armasmikeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Are you trying to change the content of an XML document that is stored on your server?  If so you will need to read the document, change the content, and write the document back into the server file system, right?  You would use file_get_contents() and file_put_contents() to read and write the document.
0
Ray PaseurCommented:
Here is the XML document:

<?xml version="1.0" encoding="utf-8"?>
<thing>InitialState</thing>

Open in new window

And here is the code that changes it:

<?php // RAY_temp_armasmike.php
error_reporting(E_ALL);


// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28261870.html
// HOW TO READ / MODIFY / SAVE AN XML DOCUMENT


// ACQUIRE THE XML DOCUMENT
$url = 'RAY_temp_armasmike.xml';
$xml = file_get_contents($url);
$obj = SimpleXML_Load_String($xml);

// SHOW THE STATE OF THE DATA
var_dump($obj);

// IF THERE IS A REQUEST TO CHANGE
if (!empty($_POST))
{
    $signal = trim($_POST['signal']);
    if (!empty($signal))
    {
        // MUTATE THE OBJECT AND RE-CREATE THE XML
        $obj->thing = $_POST['signal'];
        $xml = $obj->asXML();
        file_put_contents('RAY_temp_armasmike.xml', $xml);
        echo "<br>THE VALUE HAS BEEN CHANGED TO $obj->thing";
    }
}

// CREATE THE FORM USING HEREDOC NOTATION
$form = <<<EOD
<form method="post">
<select name="signal">
<option value=" ">Choose One</option>
<option value="y">Yes</option>
<option value="n">No</option>
<option value="m">Meh</option>
</select>
<br/><input type="submit" />
</form>
EOD;

echo $form;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
armasmikeAuthor Commented:
your help always puts me back on the right path

Thank you
0
Ray PaseurCommented:
Thanks for the points and thanks for using EE! ~Ray
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.