Page 3 of 3
Re: How to connect to local MySQL
Posted: Mon Aug 26, 2013 2:19 pm
by ECNU4271
No need, I found it.
There are 4 values so it should be :1, :2, :3, :4
It works now!
New question:
Code: Select all
If field "SignUp_Password" = field "SignUp_RePassword"
else answer error"The passwords you entered are not the same."
exit to top
end if
Why this code (to check the password and reconfirm password are the same) doesn't work?
Thanks Michael
Re: How to connect to local MySQL
Posted: Mon Aug 26, 2013 2:29 pm
by Klaus
Why using ELSE here?
Code: Select all
...
## <> = IS NOT
If field "SignUp_Password" <> field "SignUp_RePassword"
answer error"The passwords you entered are not the same."
exit to top
end if
...
P.S.
You forgot the THEN in your little script!
Re: How to connect to local MySQL
Posted: Mon Aug 26, 2013 3:09 pm
by ECNU4271
New question T_T...
Code: Select all
put "Account" into tTableName
put field "SignIn_Name" into tName
put field "SignIn_Password" into tPassword
put "SELECT PASSWORD FROM " & tTableName & "WHERE Name=tName" into tSQL
put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData
if tData <> tPassword then
answer error "Incorrect Name or Password. Please re-enter."
exit to top
end if
This is the LOGIN function I want.
However, the error msg shows tName is not recognized.
How can I let the content of a field become the condition in WHERE clause? For example, in this case, the information from field "SignIn_Name"
Thanks!!
Michael
Re: How to connect to local MySQL
Posted: Mon Aug 26, 2013 3:36 pm
by ECNU4271
keep waiting.... anyone can help me with this???
Re: How to connect to local MySQL
Posted: Mon Aug 26, 2013 4:08 pm
by Klaus
Michael,
This will only work if you really have a field NAME with content -> tName!
Code: Select all
put "SELECT PASSWORD FROM " & tTableName & "WHERE Name=tName" into tSQL
You need to add the VARIABLE! (no quotes!):
Code: Select all
put "SELECT PASSWORD FROM " & tTableName & "WHERE Name=" & tName into tSQL
Soemone suggesteed that you should do this to be sure that your SQL is correct:
That is not a too dumb hint!
Best
Klaus
Re: How to connect to local MySQL
Posted: Mon Aug 26, 2013 4:16 pm
by dave_probertGA6e24
Michael,
As Klaus said

The variable needs to be outside the quotes of your string.
You really need to take your time to get the hang of how to check for basic errors in your code. Use the:
Code: Select all
put "blah blah blah" & cr after msg
type of line to sprinkle messages and info about your variables, etc all through your code - you will find it very, very helpful to spot your mistakes.
We, on the forums, can't fix all your errors - you need to learn how to figure out these by yourself. So we can concentrate on the bigger problems you may face later

Most importantly - don't be impatient. Some of us need to sleep and spend time away from the forums.
Definitely practise with all the lessons/tutorials related to the area you are interested in, read as much as possible and try some simpler experiments until you get the hang of things. This will make your coding life a lot easier.
Hope that helps,
Dave
Re: How to connect to local MySQL
Posted: Mon Aug 26, 2013 4:27 pm
by ECNU4271
All right. I am learning how to find my mistakes myself at least......
Re: How to connect to local MySQL
Posted: Mon Aug 26, 2013 4:33 pm
by ECNU4271
Code: Select all
put "SELECT Password FROM " & tTableName & " WHERE Name=" & tName into tSQL
if my database is like this:
Name Password
Mary 123456
Jack 654321
tName is Jack.
The code above should get result as 654321.
However, the error msg is unknown column 'Jack' in 'where clause'
But if I tried Name in tName.
I got 123456
654321
Somehow it works.
I don't know why, can you explain this to me?
I think my original code should work.
Michael
Re: How to connect to local MySQL
Posted: Mon Aug 26, 2013 4:54 pm
by dave_probertGA6e24
Hi Michael,
Look back at an earlier post in this thread - regarding Quotes in Where part
Cheers,
Dave
Re: How to connect to local MySQL
Posted: Mon Aug 26, 2013 4:59 pm
by ECNU4271
Hi , Dave!
If you mean back-ticks, I have tried around Name or tName, it doesn't work.
My SQL sentence is "SELECT Password FROM Account WHERE Name=Jack"
It doesnt work even in phpMyAdmin with the same error.
I really don't know how the sentence can be possibly wrong according to the SQL WHERE tutorial .
Michael
Re: How to connect to local MySQL
Posted: Mon Aug 26, 2013 5:29 pm
by ECNU4271
I got it!
Code: Select all
put "SELECT Password FROM " & tTableName & " WHERE Name='" & tName &"'" into tSQL