I've got a simple registration form that I'm trying to put together. I'm using SQL Server 2000 and all 4 columns are set up exactly the same: nvarchar(50)
with nulls aloud. I've got IIS7 hosting the website from wwwroot (I'm just trying to get the info into the DB, and this is a development machine)
Form code:
<html>
<head>
<title>My First ASP Page</Title>
</head>
<body>
<form action="Register_User.asp" method="POST">
<table style="width:15%">
<tr>
<td>User Name:</td>
<td><input type="text" name="userName" size="20" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" size="20" /></td>
</tr>
<tr>
<td>ReEnter Password:</td>
<td><input type="password" name="rePass" size="20" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name ="email" size="20" /></td>
</tr>
<tr>
<td>Department:</td>
<td><input type="text" name="dept" size="20" /></td>
</tr>
<td><input type="submit" value="Submit" name="submitButton" /></td>
</table>
</form>
</body>
</html>
ASP code:
<html>
<head>
<title>Register User</Title>
</head>
<body bgcolor="white" text="black">
<%
If Request.Form("submitButton") <> "" Then
Username = Request.Form("userName")
Password = Request.Form("password")
Email = Request.Form("email")
Department = Request.Form("dept")
'- add code to validate
Set conn = Server.Createobject("ADODB.Connection")
conn.Open "Driver={SQL Server};Server=ACCTSERVER1\pcsnsql01;Uid=***;Pwd=***;DATABASE=DavidTest"
sql = "INSERT INTO Users (Username,Password,Email,Department) VALUES "
sql = sql & "('" & userName & "','" & password & "','" & email & "','" & dept & "')"
conn.Execute sql
conn.close
Set conn = Nothing
End If
Response.Redirect "Main_Page.asp"
%>
</body>
</html>
The Username, password and email fields populate without issue but the Department field is not showing up in any column. I'm not getting any errors. Any thoughts?
is the use of dept in your code exactly how you have it. if so it is a simple coding error.
username, password, and email all work because while you are trying to use the names from the previous form you used the same names for your variables on the next page. Department is the only exception.
VBScript is not case sensitive so while you may think you are getting the names form the previous page you are actually calling the variables you declared on that page. because your dept field is being cast to a variable named Department, when you try adding dept to your SQL Insert it is not working because the variable dept does not exist.