How to connect to local MySQL

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

ECNU4271
Posts: 93
Joined: Tue May 07, 2013 4:33 pm

Re: How to connect to local MySQL

Post by ECNU4271 » Mon Aug 26, 2013 2:19 pm

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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to connect to local MySQL

Post by Klaus » Mon Aug 26, 2013 2:29 pm

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
...
:D

P.S.
You forgot the THEN in your little script!

ECNU4271
Posts: 93
Joined: Tue May 07, 2013 4:33 pm

Re: How to connect to local MySQL

Post by ECNU4271 » Mon Aug 26, 2013 3:09 pm

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

ECNU4271
Posts: 93
Joined: Tue May 07, 2013 4:33 pm

Re: How to connect to local MySQL

Post by ECNU4271 » Mon Aug 26, 2013 3:36 pm

keep waiting.... anyone can help me with this???

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to connect to local MySQL

Post by Klaus » Mon Aug 26, 2013 4:08 pm

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:

Code: Select all

...
answer tSQL
...
That is not a too dumb hint! 8-)


Best

Klaus

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: How to connect to local MySQL

Post by dave_probertGA6e24 » Mon Aug 26, 2013 4:16 pm

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
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

ECNU4271
Posts: 93
Joined: Tue May 07, 2013 4:33 pm

Re: How to connect to local MySQL

Post by ECNU4271 » Mon Aug 26, 2013 4:27 pm

All right. I am learning how to find my mistakes myself at least......

ECNU4271
Posts: 93
Joined: Tue May 07, 2013 4:33 pm

Re: How to connect to local MySQL

Post by ECNU4271 » Mon Aug 26, 2013 4:33 pm

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

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: How to connect to local MySQL

Post by dave_probertGA6e24 » Mon Aug 26, 2013 4:54 pm

Hi Michael,

Look back at an earlier post in this thread - regarding Quotes in Where part ;)

Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

ECNU4271
Posts: 93
Joined: Tue May 07, 2013 4:33 pm

Re: How to connect to local MySQL

Post by ECNU4271 » Mon Aug 26, 2013 4:59 pm

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

ECNU4271
Posts: 93
Joined: Tue May 07, 2013 4:33 pm

Re: How to connect to local MySQL

Post by ECNU4271 » Mon Aug 26, 2013 5:29 pm

I got it!

Code: Select all

put "SELECT Password FROM " & tTableName & " WHERE Name='" & tName &"'" into tSQL

Post Reply