Hej Alle
Jeg er ret ny i forhold til xml vs. php så jeg håber nogle kan hjælpe mig med et lille problem jeg har.
Jeg har en html form, som jeg gerne vil have genereret en xml fil af, når en bruger submitter formen, og som bliver gemt et bestemt sted på min server.
Jeg ved dette kan gøres vha. php, men er ikke helt sikker på hvordan.
Min php kode
indtil videre)
$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 = "";
}
?>
Min HTML form:
<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>
Og den genererede xml fil, skal være noget i stil med nedenstånde:
<?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>
Ethvert input/løsning til dette problem vil være velkomment.
På forhånd tak!