hello.. I have already join this group.

I'm the newbie.

I have problem with my code.

I wrote in php and I use xml database.

I have 3 page in php.
first, layout for the list.
second, input for the list form
third, I want to save in xml. But, I'm not yet to save in xml.

can Help me..
here my code..
first, add_item.php

<html>
<font size="20" face="arial" color="black">
<center><b> Add item </b></center><br><hr/>
</font>

<form ACTION="" METHOD="POST">

<select name='add_item1[]' size=5 multiple>
<option value='call log'> call log</option>
<option value='SMS'> SMS </option>
<option value='people'> People </option>
<option value='Browser bookmarks '> Browser bookmarks </option>
<option value='Browser searches'>Browser searches </option>
<option value='MMS'>MMS</option>
<option value='MMS parts'>MMS parts</option>
<option value='external media'>external media</option>
<option value='external videos'>external videos</option>
<option value='internal image media'>internal image media </option>
<option value='internal video'>internal video </option>
<option value='internal thumb media'>internal thumb media</option>
<option value='IM Account'>IM Account</option>
<option value='IM Accounts'>IM Accounts</option>
<option value='IM chats'>IM chats</option>
<option value='IM contacts'>IM contacts</option>
<option value='IM invitation'>IM invitation</option>
<option value='IM providers'>IM providers</option>
<option value='IM provider setting'>IM provider setting</option>	
<option value='Contact methods'>Contact methods</option>
<option value='Contact extensions'>Contact extensions</option>
<option value='Contact groups'>Contact groups</option>
<option value='Contact Organizations'>Contact Organizations</option>
<option value='Contact Phones'>Contact Phones</option>
<option value='Contact Settings'>Contact Settings</option>	
</select>

<input type=submit name="add_item" value="add item">

</form>
</html>	

<?php
$add_item=0;
$add_item=$_POST['add_item1'];
if(is_array($add_item)){
while (list($key,$val)=each($add_item)){
echo "$val<br>";
echo "<a href='index.php?page=$val'> fill in the form </a>";
}

}

second,form_sms.php

<div id="content">
<h2 align="left">SMS</h2>
	
<FORM ACTION="" METHOD="POST" NAME="form SMS" >
<table cellpadding="0" cellspacing="0" border="0" width="634">
			
			<tr>
				<td width="14" height="29">&nbsp;</td>
				<td width="114">id :</td>
				<td><input type="Text" name="id_sms" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Thread_id :</td>
				<td><input type="text" name="thread_id" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Address :</td>
				<td><input type="text" name="address" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Person :</td>
				<td><input type="text" name="person" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Date :</td>
				<td><input type="text" name="date" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Protocol :</td>
				<td><input type="text" name="protocol" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Read :</td>
				<td><input type="text" name="read" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Status :</td>
				<td><input type="text" name="status" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Type :</td>
				<td><input type="text" name="type" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="164">Reply path present :</td>
				<td><input type="text" name="reply_path_present" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Subject :</td>
				<td><input type="text" name="subject" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Body :</td>
				<td><input type="text" name="body" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Service center :</td>
				<td><input type="text" name="service_center" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Locked :</td>
				<td><input type="text" name="locked" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Error Code :</td>
				<td><input type="text" name="error_code" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Seen :</td>
				<td><input type="text" name="seen" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Semc message priority :</td>
				<td><input type="text" name="semc_message_priority" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Parent Id :</td>
				<td><input type="text" name="parent_id" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td height="30">&nbsp;</td>
				<td width="114">Delivery status :</td>
				<td><input type="text" name="delivery_status" value="" size="25" maxlength="70"></td>
			</tr>
			<tr>
				<td>  <input type="submit" name="Submit" value="save"></td>	
				<td>  <input type="reset" name="reset" value="Reset"></td>
<td>  <input type="submit" name="back" value="back" onclick="form.action='add_item.php';"> </td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
		</table>
	</FORM>
</div>

third, I want to save in xml. but, I don't now the syntax.
when I click save, it save in xml.
Can everybody help me?
thank you.. :)

third, I want to save in xml. but, I don't now the syntax.
when I click save, it save in xml.
Can everybody help me?
thank you.. :)

You would preferably use the DOMdocument class. This is described in the PHP Manual.

First you create the DOMdocument object. Then you add the data node by node, finally you save it with ..->saveXML(). I am inserting the example from the PHP docs below:

<?php

$doc = new DOMDocument('1.0');
// we want a nice output
$doc->formatOutput = true;

$root = $doc->createElement('book');
$root = $doc->appendChild($root);

$title = $doc->createElement('title');
$title = $root->appendChild($title);

$text = $doc->createTextNode('This is the title');
$text = $title->appendChild($text);

echo "Saving all the document:\n";
echo $doc->saveXML() . "\n";

echo "Saving only the title part:\n";
echo $doc->saveXML($title);

?>

Regards
Martin

<?php

$doc = new DOMDocument('1.0');
// we want a nice output
$doc->formatOutput = true;

$root = $doc->createElement('book');
$root = $doc->appendChild($root);

$title = $doc->createElement('title');
$title = $root->appendChild($title);

$text = $doc->createTextNode('This is the title');
$text = $title->appendChild($text);

echo "Saving all the document:\n";
echo $doc->saveXML() . "\n";

echo "Saving only the title part:\n";
echo $doc->saveXML($title);

?>

thank yoy for your reply martin.

the syntax above to save one xml. isn't it?

If I have several php files and I want to save and generate in one xml.

It's possible to do that?

thank you for your attention and answer.

best regrads,
abe

<?php

$doc = new DOMDocument('1.0');
// we want a nice output
$doc->formatOutput = true;

$root = $doc->createElement('book');
$root = $doc->appendChild($root);

$title = $doc->createElement('title');
$title = $root->appendChild($title);

$text = $doc->createTextNode('This is the title');
$text = $title->appendChild($text);

echo "Saving all the document:\n";
echo $doc->saveXML() . "\n";

echo "Saving only the title part:\n";
echo $doc->saveXML($title);

?>

ok.. I have already finish to save in xml. and work it! thanks you martin.

but, I have one question.

I have several php files and I use just one xml as the database to store my data.

can I do it? It's possible?

best regrads,
abe

ok.. I have already finish to save in xml. and work it! thanks you martin.

but, I have one question.

I have several php files and I use just one xml as the database to store my data.

can I do it? It's possible?

best regrads,
abe

Sure,

you have to make sure that you insert data properly.
Load your XML-Data into a DOM-Onject using the load method.

$db = new DOMDocument();
$db->load('your_database.xml');

// some manipulations to the DOM structure would happen here

$db->save('your_database.xml');

So multiple PHP programs using one shared XML file is not a problem.
However if you do this with multiple users, you might get into trouble because these are just FILE based operations.

If user 1 comes does some editing and does not press the button for some time and in between comes user 2 does some editing then whoever is the last one who does the "Save" will win and the changes from the other one are lost.

Regards
Maba

Sure,

you have to make sure that you insert data properly.
Load your XML-Data into a DOM-Onject using the load method.

$db = new DOMDocument();
$db->load('your_database.xml');

// some manipulations to the DOM structure would happen here

$db->save('your_database.xml');

So multiple PHP programs using one shared XML file is not a problem.
However if you do this with multiple users, you might get into trouble because these are just FILE based operations.

If user 1 comes does some editing and does not press the button for some time and in between comes user 2 does some editing then whoever is the last one who does the "Save" will win and the changes from the other one are lost.

Regards
Maba

oh I see that.. thank you for your answers.

I have already try it. and it works.

but, I want to keep my old xml. if come one xml file, the old xml didn't change.

Do you have any syntax to do that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.