T
thomas
I have the below form and I want the contents of the fields to be passed to
an ASP file which then writes them to an XML file. I've used a version of
this before, I then changed it but now it doesn't work. Any ideas?
new_user.html
==========
<html>
<head>
<title>New User</title>
<link href="mystyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<form action="new_user.asp" method="post" name="new_user_form">
<table class = "one">
<tr>
<td>
<table class = "one">
<tr>
<td>Username:</td>
<td><input name="user" id="user" type="text" ></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="pass" id="pass" type="text"></td>
</tr>
</table>
<p><input type="submit" name="Submit" value="Confirm Details"></p>
<p><a href="index.html">Return to Login Page</a></p>
</td>
</tr>
</table>
</form>
</body>
</html>
new_user.asp
=========
<%@ Language="VBScript" %>
<%
dim objDom, fileExists, objFieldValue, objPI, nodes, path
Set objDom = server.CreateObject("Microsoft.XMLDOM")
objDom.preserveWhiteSpace = True
fileExists=objDom.Load(Server.MapPath("users.xml"))
If fileExists = True Then
Set objRoot = objDom.documentElement
Else
Set objRoot = objDom.createElement("members")
objDom.appendChild objRoot
End If
Set objRecord = objDom.createElement("member")
objRoot.appendChild objRecord
Set objFieldValue = objDom.createElement("username")
objFieldValue.Text = Request.Form("user")
objRecord.appendChild objFieldValue
Set objFieldValue = objDom.createElement("password")
objFieldValue.Text = Request.Form("pass")
objRecord.appendChild objFieldValue
set xmlDocument=CreateObject("MSXML2.FreeThreadedDOMDocument")
xmlDocument.async="false"
xmlDocument.load(Server.MapPath("users.xml"))
path = "members"
set nodes = xmlDocument.selectNodes(path)
If nodes.length = 0 Then
If fileExists = False Then
Set objPI=objDom.createProcessingInstruction("xml", "version='1.0'")
objDom.insertBefore objPI, objDom.childNodes(0)
End If
Else
Response.Redirect("error.html")
End If
objDom.save(Server.MapPath("users.xml"))
Response.Redirect("success.html")
%>
%>
users.xml
======
<?xml version="1.0"?>
<members>
<member>
<username>thomas</username>
<password>123456</password>
</member>
<member>
<username>martin</username>
<password>111111</password>
</member>
<member>
<username>stuart</username>
<password>654321</password>
</member>
</members>
an ASP file which then writes them to an XML file. I've used a version of
this before, I then changed it but now it doesn't work. Any ideas?
new_user.html
==========
<html>
<head>
<title>New User</title>
<link href="mystyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<form action="new_user.asp" method="post" name="new_user_form">
<table class = "one">
<tr>
<td>
<table class = "one">
<tr>
<td>Username:</td>
<td><input name="user" id="user" type="text" ></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="pass" id="pass" type="text"></td>
</tr>
</table>
<p><input type="submit" name="Submit" value="Confirm Details"></p>
<p><a href="index.html">Return to Login Page</a></p>
</td>
</tr>
</table>
</form>
</body>
</html>
new_user.asp
=========
<%@ Language="VBScript" %>
<%
dim objDom, fileExists, objFieldValue, objPI, nodes, path
Set objDom = server.CreateObject("Microsoft.XMLDOM")
objDom.preserveWhiteSpace = True
fileExists=objDom.Load(Server.MapPath("users.xml"))
If fileExists = True Then
Set objRoot = objDom.documentElement
Else
Set objRoot = objDom.createElement("members")
objDom.appendChild objRoot
End If
Set objRecord = objDom.createElement("member")
objRoot.appendChild objRecord
Set objFieldValue = objDom.createElement("username")
objFieldValue.Text = Request.Form("user")
objRecord.appendChild objFieldValue
Set objFieldValue = objDom.createElement("password")
objFieldValue.Text = Request.Form("pass")
objRecord.appendChild objFieldValue
set xmlDocument=CreateObject("MSXML2.FreeThreadedDOMDocument")
xmlDocument.async="false"
xmlDocument.load(Server.MapPath("users.xml"))
path = "members"
set nodes = xmlDocument.selectNodes(path)
If nodes.length = 0 Then
If fileExists = False Then
Set objPI=objDom.createProcessingInstruction("xml", "version='1.0'")
objDom.insertBefore objPI, objDom.childNodes(0)
End If
Else
Response.Redirect("error.html")
End If
objDom.save(Server.MapPath("users.xml"))
Response.Redirect("success.html")
%>
%>
users.xml
======
<?xml version="1.0"?>
<members>
<member>
<username>thomas</username>
<password>123456</password>
</member>
<member>
<username>martin</username>
<password>111111</password>
</member>
<member>
<username>stuart</username>
<password>654321</password>
</member>
</members>