• پایان فعالیت بخشهای انجمن: امکان ایجاد موضوع یا نوشته جدید برای عموم کاربران غیرفعال شده است

گرفتن اطلاعات از کاربر و ذخیره آن درون 2 تا دیتابیس

ramin281

کاربر تازه وارد
تاریخ عضویت
21 ژانویه 2005
نوشته‌ها
55
لایک‌ها
0
محل سکونت
شیراز
سلام

من می خواهم وقتی کاربران عضو می شوند اطلاعات آنها درون 2 تا جدول از یک دیتابیس اکسس ذخیره شود
چه تغییراتی باید در این کد دهم
"[sSql = "SELECT * FROM [members

من به این صورت تست کردم نشد

"[ sSql = "SELECT * FROM [members and second
کدها هم این است
<%@ CodePage = 65001 %>
<%
Response.expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader "pragma", "no-cache"
Response.addHeader "cache-control", "private"
Response.addHeader "cache-control", "no-cache"
Response.addHeader "cache-control", "no-store"
Response.CacheControl = "no-cache"
%>
<%
ewCurSec = 0 ' Initialise

' User levels
Const ewAllowAdd = 1
Const ewAllowDelete = 2
Const ewAllowEdit = 4
Const ewAllowView = 8
Const ewAllowList = 8
Const ewAllowReport = 8
Const ewAllowSearch = 8
Const ewAllowAdmin = 16
%>
<%
If Session("project1_status") <> "login" Then
Response.Redirect "login.asp"
End If
%>
<%

' Initialize common variables
x_ID = Null: ox_ID = Null
x_Username = Null: ox_Username = Null
x_email = Null: ox_email = Null
x_useracco = Null: ox_useracco = Null
x_pass = Null: ox_pass = Null
x_name = Null: ox_name = Null
x_tell = Null: ox_tell = Null
%>
<!--#include file="db.asp"-->
<!--#include file="aspmkrfn.asp"-->
<%
Response.Buffer = True

' Load key from QueryString
bCopy = True
x_Username = Request.QueryString("Username")
If x_Username = "" Or IsNull(x_Username) Then
bCopy = False
End If
x_email = Request.QueryString("email")
If x_email = "" Or IsNull(x_email) Then
bCopy = False
End If

' Get action
sAction = Request.Form("a_add")
If (sAction = "" Or IsNull(sAction)) Then
If bCopy Then
sAction = "C" ' Copy record
Else
sAction = "I" ' Display blank record
End If
Else

' Get fields from form
x_ID = Request.Form("x_ID")
x_Username = Request.Form("x_Username")
x_email = Request.Form("x_email")
x_useracco = Request.Form("x_useracco")
x_pass = Request.Form("x_pass")
x_name = Request.Form("x_name")
x_tell = Request.Form("x_tell")
End If

' Open connection to the database
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open xDb_Conn_Str
Select Case sAction
Case "C": ' Get a record to display
If Not LoadData() Then ' Load Record based on key
Session("ewmsg") = "No records found"
conn.Close ' Close Connection
Set conn = Nothing
Response.Clear
Response.Redirect "memberslist.asp"
End If
Case "A": ' Add
If AddData() Then ' Add New Record
Session("ewmsg") = "Add New Record Successful"
conn.Close ' Close Connection
Set conn = Nothing
Response.Clear
Response.Redirect "memberslist.asp"
Else
End If
End Select
%>
<!--#include file="header.asp"-->
<script type="text/javascript" src="ew.js"></script>
<script type="text/javascript">
<!--
EW_dateSep = "/"; // set date separator
//-->
</script>
<script type="text/javascript">
<!--
function EW_checkMyForm(EW_this) {
if (EW_this.x_Username && !EW_hasValue(EW_this.x_Username, "TEXT" )) {
if (!EW_onError(EW_this, EW_this.x_Username, "TEXT", "Please enter required field - Username"))
return false;
}
if (EW_this.x_email && !EW_hasValue(EW_this.x_email, "TEXT" )) {
if (!EW_onError(EW_this, EW_this.x_email, "TEXT", "Please enter required field - email"))
return false;
}
return true;
}
//-->
</script>
<script type="text/javascript">
<!--
var EW_HTMLArea;
//-->
</script>
<p><span class="aspmaker">Add to TABLE: members<br><br><a href="memberslist.asp">Back to List</a></span></p>
<form name="membersadd" id="membersadd" action="membersadd.asp" method="post" onSubmit="return EW_checkMyForm(this);">
<p>
<input type="hidden" name="a_add" value="A">
<%
If Session("ewmsg") <> "" Then
%>
<p><span class="aspmaker" style="color: red;"><%= Session("ewmsg") %></span></p>
<%
Session("ewmsg") = "" ' Clear message
End If
%>
<table border="0" cellspacing="1" cellpadding="4" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#3366CC"><span class="aspmaker" style="color: #FFFFFF;">Username</span></td>
<td bgcolor="#F5F5F5"><span class="aspmaker">
<input type="text" name="x_Username" id="x_Username" size="30" maxlength="50" value="<%= Server.HTMLEncode(x_Username&"") %>">
</span></td>
</tr>
<tr>
<td bgcolor="#3366CC"><span class="aspmaker" style="color: #FFFFFF;">email</span></td>
<td bgcolor="#F5F5F5"><span class="aspmaker">
<input type="text" name="x_email" id="x_email" size="30" maxlength="50" value="<%= Server.HTMLEncode(x_email&"") %>">
</span></td>
</tr>
<tr>
<td bgcolor="#3366CC"><span class="aspmaker" style="color: #FFFFFF;">useracco</span></td>
<td bgcolor="#F5F5F5"><span class="aspmaker">
<input type="text" name="x_useracco" id="x_useracco" size="30" maxlength="50" value="<%= Server.HTMLEncode(x_useracco&"") %>">
</span></td>
</tr>
<tr>
<td bgcolor="#3366CC"><span class="aspmaker" style="color: #FFFFFF;">pass</span></td>
<td bgcolor="#F5F5F5"><span class="aspmaker">
<input type="text" name="x_pass" id="x_pass" size="30" maxlength="50" value="<%= Server.HTMLEncode(x_pass&"") %>">
</span></td>
</tr>
<tr>
<td bgcolor="#3366CC"><span class="aspmaker" style="color: #FFFFFF;">name</span></td>
<td bgcolor="#F5F5F5"><span class="aspmaker">
<input type="text" name="x_name" id="x_name" size="30" maxlength="50" value="<%= Server.HTMLEncode(x_name&"") %>">
</span></td>
</tr>
<tr>
<td bgcolor="#3366CC"><span class="aspmaker" style="color: #FFFFFF;">tell</span></td>
<td bgcolor="#F5F5F5"><span class="aspmaker">
<input type="text" name="x_tell" id="x_tell" size="30" maxlength="50" value="<%= Server.HTMLEncode(x_tell&"") %>">
</span></td>
</tr>
</table>
<p>
<input type="submit" name="Action" value="ADD">
</form>
<!--#include file="footer.asp"-->
<%
conn.Close ' Close Connection
Set conn = Nothing
%>
<%

'-------------------------------------------------------------------------------
' Function LoadData
' - Load Data based on Key Value
' - Variables setup: field variables

Function LoadData()
Dim sSql, rs, sWhere, sGroupBy, sHaving, sOrderBy
sSql = "SELECT * FROM [members]"
sWhere = ""
sGroupBy = ""
sHaving = ""
sOrderBy = ""
If sWhere <> "" Then sWhere = sWhere & " AND "
sWhere = sWhere & "([Username] = '" & AdjustSql(x_Username) & "')"
If sWhere <> "" Then sWhere = sWhere & " AND "
sWhere = sWhere & "( = '" & AdjustSql(x_email) & "')"
sSql = sSql & " WHERE " & sWhere
If sGroupBy <> "" Then
sSql = sSql & " GROUP BY " & sGroupBy
End If
If sHaving <> "" Then
sSql = sSql & " HAVING " & sHaving
End If
If sOrderBy <> "" Then
sSql = sSql & " ORDER BY " & sOrderBy
End If
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sSql, conn
If rs.Eof Then
LoadData = False
Else
LoadData = True
rs.MoveFirst

' Get the field contents
x_ID = rs("ID")
x_Username = rs("Username")
x_email = rs("email")
x_useracco = rs("useracco")
x_pass = rs("pass")
x_name = rs("name")
x_tell = rs("tell")
End If
rs.Close
Set rs = Nothing
End Function
%>
<%

'-------------------------------------------------------------------------------
' Function AddData
' - Add Data
' - Variables used: field variables

Function AddData()
Dim sSql, rs, sWhere, sGroupBy, sHaving, sOrderBy
Dim bCheckKey, sSqlChk, sWhereChk
sSql = "SELECT * FROM [members]"
sWhere = ""
sGroupBy = ""
sHaving = ""
sOrderBy = ""

' Check for duplicate key
bCheckKey = True
sWhereChk = sWhere
If x_Username = "" Or IsNull(x_Username) Then
bCheckKey = False
Else
If sWhereChk <> "" Then sWhereChk = sWhereChk & " AND "
sWhereChk = sWhereChk & "([Username] = '" & AdjustSql(x_Username) & "')"
End If
If x_email = "" Or IsNull(x_email) Then
bCheckKey = False
Else
If sWhereChk <> "" Then sWhereChk = sWhereChk & " AND "
sWhereChk = sWhereChk & "([email] = '" & AdjustSql(x_email) & "')"
End If
If bCheckKey Then
sSqlChk = sSql & " WHERE " & sWhereChk
Set rsChk = conn.Execute(sSqlChk)
If Not rsChk.Eof Then
Session("ewmsg") = "Duplicate value for primary key"
rsChk.Close
Set rsChk = Nothing
AddData = False
Exit Function
End If
rsChk.Close
Set rsChk = Nothing
End If
sWhereChk = sWhere
If x_Username = "" Or IsNull(x_Username) Then ' Check field with unique index

' Ignore
Else
If sWhereChk <> "" Then sWhereChk = sWhereChk & " AND "
sWhereChk = sWhereChk & "([Username] = '" & AdjustSql(x_Username) & "')"
sSqlChk = sSql & " WHERE " & sWhereChk
Set rsChk = conn.Execute(sSqlChk)
If Not rsChk.Eof Then
Session("ewmsg") = "Duplicate value for index or primary key -- Username, value = " & x_Username
rsChk.Close
Set rsChk = Nothing
AddData = False
Exit Function
End If
rsChk.Close
Set rsChk = Nothing
End If
sWhereChk = sWhere
If x_email = "" Or IsNull(x_email) Then ' Check field with unique index

' Ignore
Else
If sWhereChk <> "" Then sWhereChk = sWhereChk & " AND "
sWhereChk = sWhereChk & "([email] = '" & AdjustSql(x_email) & "')"
sSqlChk = sSql & " WHERE " & sWhereChk
Set rsChk = conn.Execute(sSqlChk)
If Not rsChk.Eof Then
Session("ewmsg") = "Duplicate value for index or primary key -- email, value = " & x_email
rsChk.Close
Set rsChk = Nothing
AddData = False
Exit Function
End If
rsChk.Close
Set rsChk = Nothing
End If

' Add New Record
If sWhere <> "" Then sWhere = sWhere & " AND "
sWhere = sWhere & "(0 = 1)"
sSql = sSql & " WHERE " & sWhere
If sGroupBy <> "" Then
sSql = sSql & " GROUP BY " & sGroupBy
End If
If sHaving <> "" Then
sSql = sSql & " HAVING " & sHaving
End If
If sOrderBy <> "" Then
sSql = sSql & " ORDER BY " & sOrderBy
End If
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 3
rs.Open sSql, conn, 1, 2
rs.AddNew

' Field Username
sTmp = Trim(x_Username)
If Trim(sTmp) = "" Then sTmp = ""
rs("Username") = sTmp

' Field email
sTmp = Trim(x_email)
If Trim(sTmp) = "" Then sTmp = ""
rs("email") = sTmp

' Field useracco
sTmp = Trim(x_useracco)
If Trim(sTmp) = "" Then sTmp = Null
rs("useracco") = sTmp

' Field pass
sTmp = Trim(x_pass)
If Trim(sTmp) = "" Then sTmp = Null
rs("pass") = sTmp

' Field name
sTmp = Trim(x_name)
If Trim(sTmp) = "" Then sTmp = Null
rs("name") = sTmp

' Field tell
sTmp = Trim(x_tell)
If Trim(sTmp) = "" Then sTmp = Null
rs("tell") = sTmp
rs.Update
rs.Close
Set rs = Nothing
AddData = True
End Function
%>[/LEFT]​
 
بالا