By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,263 Members | 1,656 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,263 IT Pros & Developers. It's quick & easy.

want to export form input to xml using php

P: 89
Hello All

I'm quite new to xml vs. PHP, so i hope someone can help with an issue i have been struggeling with.

I have an html form, that when submitted, it should create an xml file, and save in a certain place on my server.

I know that this can be done using php, but i'm not sure how....?

Here is my php (which needs to be configured to output the xml file):

[PHP]<?php

$conn = mssql_connect('host','username','password');
mssql_select_db('databasename',$conn);

session_start();
header("Cache-control: private");
session_register("LoggedIn");
session_register("SavedSearchType");
session_register("SalesRepID");
session_register("SavedCustID");
session_register("SavedFromDate");
session_register("SavedToDate");
session_register("WebCompanyName");
session_register("CompanyName");
session_register('WebUserType');

if (!isset($_POST['CustID'])) {
$_POST['CustID'] = trim($_SESSION['SavedCustID']);
}

$_SESSION['SavedCustID'] = "All";
if (trim($_SESSION['ShowDetails']) == "Y") {
if (trim($_SESSION['WebUserType']) == "Rep") {
$_SESSION['SavedCustID'] = trim($_POST['CustID']);
}}

if ($_SESSION['LoggedIn'] != true) {
@include("./login.php");
return;
}

$a = trim($_SESSION['UserID']);
$b = trim($_SESSION['Password']);
$query = "select * from USERINFO where (UserID = '" . $a . "' and Password = '" . $b . "')";
// print($query);
$result = mssql_query($query,$conn);
if (mssql_num_rows($result) > 0) {
$userinfo = mssql_fetch_array($result);
$CompanyName = $userinfo['CompanyName'];
$Addr1 = $userinfo['Addr1'];
$Addr2 = $userinfo['Addr2'];
$City = $userinfo['City'];
$State = $userinfo['State'];
$Zip = $userinfo['Zip'];
$Country = $userinfo['Country'];
$Phone = $userinfo['Phone'];
$CustID = trim($userinfo['CustID']);
} else {
$CompanyName = "";
$Addr1 = "";
$Addr2 = "";
$City = "";
$State = "";
$Zip = "";
$Country = "";
$Phone = "";
$CustID = "";
}
?>
[/PHP]

Here is my form:

[HTML]<form method="post" name="shopform" action="" onsubmit="return checkFields3();">

<input type="hidden" name="CompanyName" value="<?php echo $CompanyName; ?>" />
<input type="hidden" name="Addr1" value="<?php echo $Addr1; ?>" />
<input type="hidden" name="Addr2" value="<?php echo $Addr2; ?>" />
<input type="hidden" name="City" value="<?php echo $City; ?>" />
<input type="hidden" name="Zip" value="<?php echo $Zip; ?>" />
<input type="hidden" name="Country" value="<?php echo $Country; ?>" />
<input type="hidden" name="Phone" value="<?php echo $Phone; ?>" />
<input type="hidden" name="CustID" value="<?php echo $CustID; ?>" />

<table>
<tr>
<td>
<input name="part_name" type="text" size="30" />
</td>
</tr>
<tr>
<td>
<input name="layers" value="2" type="radio" />
<input name="layers" value="4" type="radio" />
<input name="layers" value="6" type="radio" />
<input name="layers" value="8" type="radio" />
</td>
</tr>
<tr>
<td>
<input name="quantity" type="text" value="" size="5" />
</td>
</tr>
<input name="pcbwidth" type="text" value="" size="5" />
<input name="pcbheight" type="text" value="" size="5" />
</td>
</tr>
<tr>
<td>
<input name="thickness" value="1.0" type="radio" />
<input name="thickness" value="1.6" type="radio" />
<input name="thickness" value="2.0" type="radio" />
</td>
</tr>
<tr>
<td>
<input name="cuoutthickness" type="radio" value="35 " />
<input name="cuoutthickness" type="radio" value="70 " />
</td>
</tr>
<tr>
<td>
<input name="surface" value="Silver" type="radio" />
<input name="surface" value="Leadfree HAL" type="radio" />
</td>
</tr>
<tr>
<td>
<input name="delivery" value="5 Working Days" type="radio" />
<input name="delivery" value="8 Working Days" type="radio" />
<input name="delivery" value="10 Working Days" type="radio" />
<input name="delivery" value="15 Working Days" type="radio" />
</td>
</tr>
</table>
</form>[/HTML]

And the generated xmlfile should look something similar to this:

[HTML]<?xml version="1.0" encoding="UTF-8"?>
<Header>xxxxx</Header>
- <Customer_Info>
<Company_name>xxxxx</Company_name>
<Address>xxxxx</Address>
<City>xxxxx</City>
<Zip>xxxxx</Zip>
<Country>xxxxx</Country>
<CustID>xxxxx</CustID>
</Customer_Info>
- <CAD_Data>
<part_name>xxxxxxx</part_name>
<layers>xxxxxxx</layers>
<quantity>xxxxxxx</quantity>
<pcbwidth>xxxxxxx</pcbwidth>
<pcbheight>xxxxxxx</pcbheight>
<thickness>xxxxxxx</thickness>
<copperthickness>xxxxxxx</copperthickness>
<delivery>xxxxxxx</delivery>
</CAD_Data>[/HTML]

Any input/solution to this problem is more than welcome.

Thanks in advance!
Aug 26 '08 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
If cou can make allowances to the structure of the xml file you can have a look at WDDX. this essentially serializes variables (e.g. arrays) into xml.
WDDX at Wikipedia
Aug 28 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.