עבור לתוכן

שתי שאלות פשוטות, Js וSQL

Featured Replies

פורסם

שלום, שתי שאלות פשוטות, אבל לצערי לא הצלחתי לפתור וזה די דחוף..

הראשונה, יש לי דף HTML עם כמה כפתורי רדיו (שם הקבוצה - role), איך אני יכול בעזרת Js לוודא שאחד מהכפתורים מסומן?

השנייה, איך הולך תנאי מורכב במשפט Select? משהו בסגנון של (select * from XXX where (name=abc AND pass=123? מה הסינטקס המדוייק?

תודה רבה!

  • תגובות 39
  • צפיות 2.9k
  • נוצר
  • תגובה אחרונה
פורסם

קוד בשביל ה SQL >>>


SELECT * FROM users
WHERE users.name like '%whatever%' AND users.password like '%whatever%'

תשנה רק את שם הטבלאות ואת ה whatever תשאיר את סימני ה % לפני ואחרי השם והסיסמה הם בודקים שהשם הוא במדיוק כמו שהכנסת ולא חלק ממשהו למשל

hello ו hello2 יעברו את זה שניהם אם תוריד את ה%

פורסם

1) תחפש בגוגל JS RADIOBOX, אולי תמצא משהו.

2)הסינטקס הוא בידיוק מה שרשמת, רק שחסר לך ' מסביב למחרוזות.

select * from XXX where name = 'abc' and pass = '123'

עריכה: לא כדאי לך לעשות את השאילתא שלך ככה, מכיוון שהיא פרוצה לSQL INJECTIONS.

תשלוף את כל הרשומות עם אותו שם משתמש, ותבדוק האם הסיסמא שווה. לדוגמא בASP:





sqlcmd = "select pass from XXX where name = 'abc'"
set rs = conn.execute(sqlcmd)
if not rs.eof
if rs("pass") == "123" then
'all ok now, the user is logged in..
'make sure u save it in session or cookies
else
'bad password

end if
else
'no user
end if

פורסם
  • מחבר

עריכה:

תודה רבה, הJS עובד.

עכשיו, האם הקוד הבא תקין?

pname=request.form("pname")
role=request.form("role")
team=request.form("team")
minH=request.form("minHeight")
maxH=request.form("maxHeight")

sestr="select * from player where "
if pname<>"" then
sestr=sestr&"pname='"&pname&"' AND "
end if
if role<>"" then
sestr=sestr&"role='"&role&"' AND "
end if
if team<>"" then
sestr=sestr&"team='"&team&"' AND "
end if
if minH<>"" then
sestr=sestr&"minH>'"&minH&"' AND "
end if
if maxH<>"" then
sestr=sestr&"maxH<'"&maxH&"' AND "
end if

כמובן שבהנחה שחותכים את הAND האחרון.. (אם מישהו יגיד לי איך לעשות זאת, זה יהיה נפלא)[br]פורסם בתאריך: 30.06.2007 בשעה 15:17:19


סליחה על ההקפצה, אבל זה די לחוץ...

זאת השאילתא הסופית, האם היא תקינה?

select * from player where pname='fdsa' AND role='sf' AND team='tre' AND minH>'213' AND maxH<'354' 

פורסם

באיזה אופן / שיטה אתה משתמש לשליחת הנתונים ב-ASP ?

פורסם
  • מחבר
<html>

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1255">
</head>
<body>
<%
pname=request.form("pname")
role=request.form("role")
team=request.form("team")
minH=request.form("minHeight")
maxH=request.form("maxHeight")

sestr="select * from player where "
if pname<>"" then
sestr=sestr&"pname='"&pname&"' AND "
end if
if role<>"" then
sestr=sestr&"role='"&role&"' AND "
end if
if team<>"" then
sestr=sestr&"team='"&team&"' AND "
end if
if minH<>"" then
sestr=sestr&"minH>'"&minH&"' AND "
end if
if maxH<>"" then
sestr=sestr&"maxH<'"&maxH&"' AND "
end if

path=Server.mappath("../DATABASE/db.mdb")

Set oConn = Server.createobject("ADODB.Connection")

oConn.open "driver={microsoft access driver (*.mdb)}; DBQ="&path

set oRs=server.createobject("ADODB.Recordset")

mysql="select * from players"

oRs.open mysql, oConn ,2, 2

if oRs.eof and oRs. bof then
response.write "Player was not found</br>"
response.write "<a href = '../html/search player.htm'>Search_again</a>"
else

response.write "<table border='1%'>"
response.write "<tr><td>Name</td><td>Role</td><td>Height</td><td>team</td></tr>"
Ors.movefirst
do until oRs.eof
response.write "<tr>"
response.write "<td>"&oRs.fields("pname")&"</td>"
role=oRs.fields("role")
if role="" then
response.write "<td>Unknow</td>"
else
response.write "<td>"&oRs.fields("role")&"</td>"
end if
Height=oRs.fields("Height")
if Height="" then
response.write "<td>Unknow</td>"
else
response.write "<td>"&oRs.fields("Height")&"</td>"
end if
team=oRs.fields("team")
if team="" then
response.write "<td>Unknow</td>"
else
response.write "<td>"&oRs.fields("team")&"</td>"
end if
response.write "<td><a href = '../players/"&oRs.fields("pname")&".asp'>player page</a></td>"
response.write "</tr>"
oRs.movenext
loop
response.write sestr
end if
oRs.close
set oRs = nothing
oConn.close
Set oConn = nothing
%>
</div>
</body>

</html>

פורסם

יש לך בעיה של ניגודיות בין שתי הקודים ...

באיזה שיטה לשליחת הנתונים מהטופס אתה משתמש ? POST או GET

תגיד לנו וכך נוכל יותר טוב לעזור לך....

פורסם
  • מחבר

POST

אגב, הניגוד בין הקודים הוא שבמשפט חתכתי ידנית את הAND האחרון... אם מישהו יוכל להגיד לי איך אני עושה זאת בASP, מה טוב.

פורסם

1


path=Server.mappath("../DATABASE/db.mdb")

2


Set oConn = Server.createobject("ADODB.Connection")

3


oConn.open "driver={microsoft access driver (*.mdb)}; DBQ="&path

4


set oRs=server.createobject("ADODB.Recordset")

בקוד 1 אין צורך ב-"/...." לפני מיקום מסד הנתונים

רשמת פעמיים את אותו קוד בתוכנית (קוד 2ו-4) תמחק אחד מהם....

אין צורך בקוד 3 משום ששם מסד הנתונים מסתיים ב mdb אז מסד הנתונים שייך ל-ACCESS ולכן אין צורך לציין זאת...

פורסם
  • מחבר

1. הדף והDB לא באותה תיקיה.

2+4. לא אותו קוד

3. נכון, אבל זה לא מזיק.

פורסם

1. כאשר הדף נמצא בתיקיה הראשית והמסד ותיקיה משנית אז צריך לכתוב רק את שם התיקייה ושם המסד....

פורסם

אתה יכול לעשות משהו כזה


sqlcmd = "select * from bla"
conds = ""
if needMoreCond then
if conds <> "" then
conds = conds & " and"
else
conds = " where"
end if
conds = conds & " a = condition"

end if

פורסם
  • מחבר

תודה רבה רבה!

עכשיו רק נשאר להגביל בJS את ההקלדה בתאים ספציפיים לאותיות/מספרים בלבד, וסיימתי את הכל.

פורסם

תודה רבה רבה!

עכשיו רק נשאר להגביל בJS את ההקלדה בתאים ספציפיים לאותיות/מספרים בלבד, וסיימתי את הכל.

פרט יותר......

פורסם
  • מחבר

יש לי בטופס שני שדות, אחד אמור להכיל רק מספרים, והשני רק אותיות.

יש איזשהי פקודה בJS לבדוק את זה, אבל אני לא ממש זוכר אותה...

אם מישהו מכיר הוא מוזמן לספר, ואם לא אני אמצא את זה איפשהו...

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים