-
Re: connection between SQL Server 2. and dreamweaver??
well, is the problem solved?
by the way, if some field name is a reserved word, like "ORDER" you can still use it, just have to write like select [order] from tblWhatever where....
-
Re: connection between SQL Server 2. and dreamweaver??
well, if problem is solved, don't need to paste
-
Re: connection between SQL Server 2. and dreamweaver??
OOohh, ok
Thank you :-)
Another question. Why am i getting this other error after i fill the balnks and press submit.?? It says Invalid column name..
-
Re: connection between SQL Server 2. and dreamweaver??
his is the error:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'Edith'.
/user.asp, line 8
This is the code:
<!--#include File="conn.asp"-->
<%
if Request.ServerVariables("REQUEST_METHOD") = "POST" then
sNtID = request("NtID")
Set RS=CreateObject("ADODB.Recordset")
sql="select * from UserTbl where NtId = '" & sNtID & "' or UserFirstName = " & request("UserFirstName")
Rs.Open sql,conn,1,3
If RS.eof then
rs.addnew
rs("NtId") = sNtID
rs("UserFirstName") = request("UserFirstName")
rs("UserLastName") = request("UserLastName")
rs("UserRoles") = request("UserRoles")
rs("UserEmail") = request("UserEmail")
rs("CreatedDate") = Date
rs("LastUpdate") = Date
rs.update
else
response.write "<p align='center'><font face='verdana' size='2' color='red'>The user you entered, " & sNtID & ", is already in the database, so it was not added.</font></p>"
end if
end if
%>
<% if err.number <>0 then
response.write err.description
end if %>
<html>
<head>
<script language="javascript">
function checkinput(){
//use this Javascript function to see what the user entered before submitting.
if (newuser.UserFirstName.value == "")
{alert("You have to enter a user name.");
newuser.UserFirstName.focus();
return false;}
if (newuser.UserLastName.value == "")
{alert("You have to enter a user Last name.");
newuser.UserLastName.focus();
return false;}
if (newuser.NtID.value == "")
{alert("You have to enter a user number.");
newuser.NtID.focus();
return false;}
if (newuser.UserRoles.value == "")
{alert("You have to enter a user roles name.");
newuser.UserRoles.focus();
return false;}
if (newuser.UserEmail.value == "")
{alert("You have to enter a user email.");
newuser.UserEmail.focus();
return false;}
if (IsNumeric(newuser.NtID.value) == false)
{alert("The user ID must be a number.");
newuser.NtID.focus();
return false;}
}
function IsNumeric(sText)
{
//this function checks if some text is a number or not
if (sText.length > 1 && sText.charAt(0)=="0")
{ IsNumber = false;
return IsNumber}
var ValidChars = "0123456789";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
}
}
return IsNumber;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>
<%'here is the form to add new records!%>
<form name="newuser" id="newuser" Method="Post" onSubmit="return checkinput();">
<table cellpadding="4" cellspacing="1" border="0" width="75%" align="center" bgcolor="000082">
<tr>
<td height="37" colspan="2" bgcolor="#000082"><font face="verdana, arial, helvetica" size="2" color="#F0F0F0"><b>Adding
a New User</b></font><font face="verdana,arial,helvetica" size="1" color="#F0f0f0"> Here
you add new user records to the database.</font></td>
</tr>
<tr>
<td width="55%" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" ><b>User ID Number</b><br>
</font> <font face="verdana,arial,helvetica" size="1" >Enter a user number (no decimals).</font></td>
<td width="45%" align="center" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" >
<input type="text" name="NtID" id="NtID" maxlength="10" size="10">
</font></td>
</tr>
<tr>
<td width="55%" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" ><b>User Name</b><br>
</font> <font face="verdana,arial,helvetica" size="1" >Enter a user name (up to 30 characters).</font></td>
<td width="45%" align="center" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" >
<input type="text" name="UserFirstName" id="UserFirstName" maxlength="30" size="30">
</font></td>
</tr>
<tr>
<td width="55%" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" ><b>User Last Name</b><br>
</font> <font face="verdana,arial,helvetica" size="1" >Enter a user last name (up to 30 characters).</font></td>
<td width="45%" align="center" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" >
<input type="text" name="UserLastName" id="UserLastName" maxlength="30" size="30">
</font></td>
</tr>
<tr>
<td width="55%" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" ><b>User Role Name</b><br>
</font> <font face="verdana,arial,helvetica" size="1" >Enter a user role name (up to 30 characters).</font></td>
<td width="45%" align="center" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" >
<input type="text" name="UserRoles" id="UserRoles" maxlength="30" size="30">
</font></td>
</tr>
<tr>
<td width="55%" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" ><b>User Email</b><br>
</font> <font face="verdana,arial,helvetica" size="1" >Enter a user email (up to 30 characters).</font></td>
<td width="45%" align="center" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" >
<input type="text" name="UserEmail" id="UserEmail" maxlength="30" size="30">
</font></td>
</tr>
<tr bgcolor="#000082">
<td colspan="2"><font face="verdana, arial, helvetica" size="2" >
</font></td>
</tr>
</table>
<p align="center"><input type="submit" class="bginput" value="Submit"></p>
</form>
<%'end of add records form%>
<%'here is where you show the records%>
<table width="25%" align="center" bgcolor="#c0c0c0" cellspacing="1">
<tr>
<td width="25%" align="center" bgcolor="#ffffff"><b>Number</b></td>
<td width="25%" align="center" bgcolor="#ffffff"><b>Name</b></td>
<td width="25%" align="center" bgcolor="#ffffff"><b>Last Name</b></td>
<td width="25%" align="center" bgcolor="#ffffff"><b>Roles</b></td>
<td width="25%" align="center" bgcolor="#ffffff"><b>Email</b></td>
<td width="25%" align="center" bgcolor="#ffffff"><b>Created</b></td>
<td width="25%" align="center" bgcolor="#ffffff"><b>Updated</b></td>
</tr>
<%
SET rs=CreateObject("ADODB.Recordset")
sql="select * from UserTbl Order by CreatedDate ASC"
rs.Open sql,Conn,1,2
do until rs.eof
%>
<tr>
<td width="25%" align="center" bgcolor="#ffffff"><%=rs("NtID")%></td>
<td width="25%" align="center" bgcolor="#ffffff"><%=rs("UserFirstName")%></td>
<td width="25%" align="center" bgcolor="#ffffff"><%=rs("UserLastName")%></td>
<td width="25%" align="center" bgcolor="#ffffff"><%=rs("UserRoles")%></td>
<td width="25%" align="center" bgcolor="#ffffff"><%=rs("UserEmail")%></td>
<td width="25%" align="center" bgcolor="#ffffff"><%=rs("CreatedDate")%></td>
<td width="25%" align="center" bgcolor="#ffffff"><%=rs("LastUpdate")%></td>
</tr>
<%rs.movenext
loop%>
</table>
</body>
</html>
-
Re: connection between SQL Server 2. and dreamweaver??
This is line 8: Rs.Open sql,conn,1,3
-
Re: connection between SQL Server 2. and dreamweaver??
should be
or UserFirstName = '" & request("UserFirstName") & "'"
-
Re: connection between SQL Server 2. and dreamweaver??
when you get line error RS.Open, that means your SQL statement has error.
since you didn't use ' ', the SQL thinks EDITH is a field name
-
Re: connection between SQL Server 2. and dreamweaver??
also, your second table is now only 25%. I guess it must be very narrow!
what i said before is this:
<table width="50%" or "80%" or "100%" or whatever,
but the <TD>'s should add up to 100
for example, if you have 5 td's, they should be <width="20%"> (average of course)
notice my first table has 2 columns, one at 55% of the table width, one at 45%
in my other table, there were 4 columns, all 25%, in both tables 100% is used
table width doesn't matter.
-
Re: connection between SQL Server 2. and dreamweaver??
Like this:
sql="select * from UserTbl where NtId = '" & sNtID & "' or UserFirstName = " & request("UserFirstName")
Cause it still sending me an error
-
Re: connection between SQL Server 2. and dreamweaver??
sql="select * from UserTbl where NtId = '" & sNtID & "' or UserFirstName = " & request("UserFirstName")
should be:
sql="select * from UserTbl where NtId = '" & sNtID & "' or UserFirstName = '" & request("UserFirstName") & "'"
-
Re: connection between SQL Server 2. and dreamweaver??
here is the basic rule in sql
where sometext = 'Edith'
where somenumber = 555
when using number fields you can do this way:
where mynum=" & tNumber
but when doing text, must be:
where mytext = '" & sText & "'"
And that's the rule
-
Re: connection between SQL Server 2. and dreamweaver??
Right did the columns but, does it still mean, the invalid column name, that the width of my table is not adding up?
The table is too big? or too small?
I did the change and the table looks big enough :-)
-
Re: connection between SQL Server 2. and dreamweaver??
-
Re: connection between SQL Server 2. and dreamweaver??
New error:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E2F)
[Microsoft][ODBC SQL Server Driver][SQL Server]INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_User_User-Training'. The conflict occurred in database 'copla-bi3dc-stage', table 'User-Training', column 'NtID'.
/user.asp, line 18
-
Re: connection between SQL Server 2. and dreamweaver??
table width not related to code problem.
html is not code (not really, it's just formatting)
code is ASP here, anything inside <% %>
html code cannot make errors, it can only make strange looking pages
the invalid column name is because you didn't put ' ' around your request("userfirstname")
OK.
imagine you are sql and you are trying to read this sentence:
select * from tblWhatever where username = password
and this sentence:
select * from tblWhatever where username = 'password'
see, they are different.
in the first, it means, username and password are the same
in the second it means my username is "password"
so when you are comparing in SQL with "WHERE" you should put string variables inside ''
like:
where name = ' " & request("something") & " ' "
but no spaces:
where name = '" & request("something") & "'"
OK?
-
Re: connection between SQL Server 2. and dreamweaver??
hmm..
I guess your NTID column is set as auto-increment, so that you cannot assign this number.
Check that it is not set as auto-increment.
-
Re: connection between SQL Server 2. and dreamweaver??
-
Re: connection between SQL Server 2. and dreamweaver??
-
Re: connection between SQL Server 2. and dreamweaver??
if NTID is set as IDENTITY YES in SQL Server, you should change it to IDENTITY NO
or just remove this line:
rs("NtId") = sNtID
and your page will work. but if you do that, you cannot control this number.
up to you.
-
Re: connection between SQL Server 2. and dreamweaver??
No the NtID is Int
but now the html is visible. The problem seems to be solve, thanks to u.
Ok what's the next step !!
How do i modify my data? After being submitted
-
Re: connection between SQL Server 2. and dreamweaver??
no problem. just follow the instruction like this:
-
Re: connection between SQL Server 2. and dreamweaver??
No, i cant remove it... it's not up to me (my boss)
But it's solve, i change the code to the way u told me.
-
Re: connection between SQL Server 2. and dreamweaver??
-
Re: connection between SQL Server 2. and dreamweaver??
sorry, I have to stop first. I think your code is in danger because your table has no unique IDENTITY Field. This will make it very difficult to control the data. For example, when somebody edits the data and change the NTID number or username, maybe two or three will have the same number. But SQL Server cannot distinguish one from another.
I suggest you have an ID field in the table of Users that is set as INT, IDENTITY YES (NOT FOR REPLICATION)
then you can proceed with edit data. It is for stability of your database that you have to take this step.
-
Re: connection between SQL Server 2. and dreamweaver??
Add the ID field to your table and then post the whole user.asp page code to me. I will modify it to be an edit data page and send it back to you.
But it's late here. I'm going offline. Send the page up again and I will send it back to you tomorrow when I am at the office.
-
Re: connection between SQL Server 2. and dreamweaver??
-
Re: connection between SQL Server 2. and dreamweaver??
Ok, thank u.
This is the new ID: UserID
And here is the code:
<!--#include File="conn.asp"-->
<%
if Request.ServerVariables("REQUEST_METHOD") = "POST" then
sNtID = request("NtID")
Set RS=CreateObject("ADODB.Recordset")
sql="select * from UserTbl where NtId = '" & sNtID & "' or UserFirstName = '" & request("UserFirstName") & "'"
Rs.Open sql,conn,1,3
If RS.eof then
rs.addnew
rs("NtId") = sNtID
rs("UserFirstName") = request("UserFirstName")
rs("UserLastName") = request("UserLastName")
rs("UserRoles") = request("UserRoles")
rs("UserEmail") = request("UserEmail")
rs("CreatedDate") = Date
rs("LastUpdate") = Date
rs.update
else
response.write "<p align='center'><font face='verdana' size='2' color='red'>The user you entered, " & sNtID & ", is already in the database, so it was not added.</font></p>"
end if
end if
%>
<% if err.number <>0 then
response.write err.description
end if %>
<html>
<head>
<script language="javascript">
function checkinput(){
//use this Javascript function to see what the user entered before submitting.
if (newuser.UserFirstName.value == "")
{alert("You have to enter a user name.");
newuser.UserFirstName.focus();
return false;}
if (newuser.UserLastName.value == "")
{alert("You have to enter a user Last name.");
newuser.UserLastName.focus();
return false;}
if (newuser.NtID.value == "")
{alert("You have to enter a user number.");
newuser.NtID.focus();
return false;}
if (newuser.UserRoles.value == "")
{alert("You have to enter a user roles name.");
newuser.UserRoles.focus();
return false;}
if (newuser.UserEmail.value == "")
{alert("You have to enter a user email.");
newuser.UserEmail.focus();
return false;}
if (IsNumeric(newuser.NtID.value) == false)
{alert("The user ID must be a number.");
newuser.NtID.focus();
return false;}
}
function IsNumeric(sText)
{
//this function checks if some text is a number or not
if (sText.length > 1 && sText.charAt(0)=="0")
{ IsNumber = false;
return IsNumber}
var ValidChars = "0123456789";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
}
}
return IsNumber;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>
<%'here is the form to add new records!%>
<form name="newuser" id="newuser" Method="Post" onSubmit="return checkinput();">
<table cellpadding="4" cellspacing="1" border="0" width="75%" align="center" bgcolor="000082">
<tr>
<td height="37" colspan="2" bgcolor="#000082"><font face="verdana, arial, helvetica" size="2" color="#F0F0F0"><b>Adding
a New User</b></font><font face="verdana,arial,helvetica" size="1" color="#F0f0f0"> Here
you add new user records to the database.</font></td>
</tr>
<tr>
<td width="55%" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" ><b>User ID Number</b><br>
</font> <font face="verdana,arial,helvetica" size="1" >Enter a user number (no decimals).</font></td>
<td width="45%" align="center" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" >
<input type="text" name="NtID" id="NtID" maxlength="10" size="10">
</font></td>
</tr>
<tr>
<td width="55%" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" ><b>User Name</b><br>
</font> <font face="verdana,arial,helvetica" size="1" >Enter a user name (up to 30 characters).</font></td>
<td width="45%" align="center" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" >
<input type="text" name="UserFirstName" id="UserFirstName" maxlength="30" size="30">
</font></td>
</tr>
<tr>
<td width="55%" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" ><b>User Last Name</b><br>
</font> <font face="verdana,arial,helvetica" size="1" >Enter a user last name (up to 30 characters).</font></td>
<td width="45%" align="center" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" >
<input type="text" name="UserLastName" id="UserLastName" maxlength="30" size="30">
</font></td>
</tr>
<tr>
<td width="55%" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" ><b>User Role Name</b><br>
</font> <font face="verdana,arial,helvetica" size="1" >Enter a user role name (up to 30 characters).</font></td>
<td width="45%" align="center" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" >
<input type="text" name="UserRoles" id="UserRoles" maxlength="30" size="30">
</font></td>
</tr>
<tr>
<td width="55%" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" ><b>User Email</b><br>
</font> <font face="verdana,arial,helvetica" size="1" >Enter a user email (up to 30 characters).</font></td>
<td width="45%" align="center" bgcolor="#DFDFDF"><font face="verdana, arial, helvetica" size="2" >
<input type="text" name="UserEmail" id="UserEmail" maxlength="30" size="30">
</font></td>
</tr>
<tr bgcolor="#000082">
<td colspan="2"><font face="verdana, arial, helvetica" size="2" >
</font></td>
</tr>
</table>
<p align="center"><input type="submit" class="bginput" value="Submit">
<input type="reset" name="Reset" value="Clear">
</p>
</form>
<%'end of add records form%>
<%'here is where you show the records%>
<table width="100%" align="center" bgcolor="#c0c0c0" cellspacing="1">
<tr>
<td width="14.2%" align="center" bgcolor="#ffffff"><b>Number</b></td>
<td width="14.2%" align="center" bgcolor="#ffffff"><b>Name</b></td>
<td width="14.2%" align="center" bgcolor="#ffffff"><b>Last Name</b></td>
<td width="14.2%" align="center" bgcolor="#ffffff"><b>Roles</b></td>
<td width="14.2%" align="center" bgcolor="#ffffff"><b>Email</b></td>
<td width="14.2%" align="center" bgcolor="#ffffff"><b>Created</b></td>
<td width="14.2%" align="center" bgcolor="#ffffff"><b>Updated</b></td>
</tr>
<%
SET rs=CreateObject("ADODB.Recordset")
sql="select * from UserTbl Order by CreatedDate ASC"
rs.Open sql,Conn,1,2
do until rs.eof
%>
<tr>
<td width="14.2%" align="center" bgcolor="#ffffff"><%=rs("NtID")%></td>
<td width="14.2%" align="center" bgcolor="#ffffff"><%=rs("UserFirstName")%></td>
<td width="14.2%" align="center" bgcolor="#ffffff"><%=rs("UserLastName")%></td>
<td width="14.2%" align="center" bgcolor="#ffffff"><%=rs("UserRoles")%></td>
<td width="14.2%" align="center" bgcolor="#ffffff"><%=rs("UserEmail")%></td>
<td width="14.2%" align="center" bgcolor="#ffffff"><%=rs("CreatedDate")%></td>
<td width="14.2%" align="center" bgcolor="#ffffff"><%=rs("LastUpdate")%></td>
</tr>
<%rs.movenext
loop%>
</table>
</body>
</html>
-
Re: connection between SQL Server 2. and dreamweaver??
ok. got it. I'll edit the page and send it up later.
-
1 Attachment(s)
Re: connection between SQL Server 2. and dreamweaver??
OK.
I have zipped the two files and attached to this post.
If you see any code you don't understand, ask me.
This is a basic model of add and edit data.
If you can understand all the code, you should have no problem accomplishing other tasks with SQL Server.
-
Re: connection between SQL Server 2. and dreamweaver??
Hello,
thank you for the zipped files.
I read both codes and i'm still studying it . Then i run the page, but there's an error:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '='.
/edituser.asp, line 35
And line 35 is this:
Rs.Open sql,conn,1,3
In the edituser.asp
And in the user.asp, there's another error:
Error Type:
ADODB.Recordset (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name or ordinal.
/user.asp, line 157
line 157:
<td width="10%" align="left" bgcolor="#ffffff"><a href="edituser.asp?id=<%=rs("UserID")%>"><%=rs("NtID")%></a></td>
And to be honest I don't understand it, why did you write both ID's? (user and NT)
Thank you again,
-
Re: connection between SQL Server 2. and dreamweaver??
hmm.
i am confused too. Yesterday my meaning about add a new ID column is to add one that is autoincrement. I guessed you added that in ADDITION To your NTID.
The point is that there should be one column in the table whose value is not set by you, it is set automatically by sql server. Without this, it is very easy to make errors in modifying data.
So, do you have an int column set as IDENTITY YES (NOT FOR REPLICATION)?
-
Re: connection between SQL Server 2. and dreamweaver??
Yes, it's UserID.
Ok, so i have two UserID and NtID. Do i delete NtID?
:-)
-
Re: connection between SQL Server 2. and dreamweaver??
I thought you wanted to keep one which is set by you, called NTID, and one that is set by SQL Server, called USERID. If you have that, my pages should work correctly.
-
Re: connection between SQL Server 2. and dreamweaver??
if you have already deleted NTID and now you add it again, you should add the number values directly in SQL SERVER the first time before you run the pages.
-
Re: connection between SQL Server 2. and dreamweaver??
Yes, that's what i want.
NtId is set by me, and UserID is the unique number.
But what's the meaning of the errror ?
Now i'm more confused...
-
Re: connection between SQL Server 2. and dreamweaver??
No, i haven't touch a thing.
-
Re: connection between SQL Server 2. and dreamweaver??
ok.
so your db has one column
NTID set as INT, Identity NO
and
USERID set as INT, Identity Yes
is it right?
so try to run your user.asp page again and tell me the error.
-
Re: connection between SQL Server 2. and dreamweaver??
Do you know about QuickBook?
-
Re: connection between SQL Server 2. and dreamweaver??
sorry. it's my mistake
change line 7 to this:
sql="select * from UserTbl where NtId = " & sNtID
and you will be OK!
-
Re: connection between SQL Server 2. and dreamweaver??
I don't think is really keeping the data, is not in the db.