0
votes

this is my first question on stackoverflow, I hope someone can help me.

I am making a website similar to facebook. heres my sql.

    readsql = "SELECT * FROM post INNER JOIN ubuser ON (post.pos_USERID = ubuser.usr_ID) WHERE ubuser.usr_ID == '"session("ID")"'"

and heres the error im getting

Microsoft VBScript compilation error '800a0401'

Expected end of statement

/student/S0215538/newsfeed1.asp, line 22

readsql = "SELECT * FROM post INNER JOIN ubuser ON (post.pos_USERID = ubuser.usr_ID) WHERE ubuser.usr_ID == ' "session("ID")" ' "
--------------------------------------------------------------------------------------------------------------^

I cant see why I am getting this error, if i comment out the WHERE onwards, it works, but its not what I need.

thanks in advance

Thanks everyone, that was fast. I always forget the &, and the people who mentioned the == should be =, you were also right. it fixed that error, however i now have a new error saying "Data type mismatch in criteria expression" in this line post.Open readsql, connection, adOpenkeyset, AdLockOptimistic "post" is my recordset and "connection" is the adodb connection.

4

4 Answers

1
votes

String concatenation required &:

readsql = "SELECT * FROM post INNER JOIN ubuser ON (post.pos_USERID = ubuser.usr_ID) WHERE ubuser.usr_ID = '" & session("ID") & "'"

Also use only one = in your query.

0
votes

Needs to be

readsql = "SELECT * FROM post INNER JOIN ubuser ON (post.pos_USERID = ubuser.usr_ID) WHERE ubuser.usr_ID = '" & session("ID") & "'"

Problem is your syntax, strings need to be terminated with double quotes " and concatenated correctly using ampersand & in VBScript. Also remove the == and replace with = as RedFilter suggested.

0
votes

try

readsql = "SELECT * FROM post INNER JOIN ubuser ON (post.pos_USERID = ubuser.usr_ID) WHERE ubuser.usr_ID = '" & session("ID") & "'"
0
votes

You need to concatenate (&) the variable session("ID") into the string:

>> set session = CreateObject("Scripting.Dictionary")
>> session("ID") = "whatever"
>> readsql = "SELECT * FROM post INNER JOIN ubuser ON (post.pos_USERID = ubuser.usr_ID) WHERE ubuser.usr_ID ==
 '" & session("ID") & "'"
>> WScript.Echo readsql
>>
SELECT * FROM post INNER JOIN ubuser ON (post.pos_USERID = ubuser.usr_ID) WHERE ubuser.usr_ID == 'whatever'
>>

(Are you sure that your DBMS' SQL dialect uses "==" for comparisons?)