Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Need help with MySQL Login code

Author
Message
Mugen Wizardry
User Banned
Posted: 13th Nov 2010 23:59 Edited at: 14th Nov 2010 02:23
Hi all. I'm having a few problems with my game's login system. I am currently using CattleRustler's MySQL plugin, IanM's Hash MD5() function, and a new plugin which I am beta testing called the X Plugin.

If someone could take the time to help, I would greatly appreciate it!

Here's the code:



the above is based on THIS code to keep it from reading an empty string:



I basically need to know how to get it to stop giving me this error:

Warning: `Unknown column `testuser` in WHERE clause`

I also need to know how to make it stop giving me THIS error as well using something that counts the number of rows and makes sure they are > 0 before calling mysql_query():

Warning: `There is no row at position 1`

The 1st error happens if you take out the chr$(34)'s in the renderquery$ clause

The 2nd error happens if you leave the chr$(34)'s in the renderquery$ clause


The query is called like this, and the row count is checked like this:



EDIT:

Here are the functions:



Thanks for reading!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 14th Nov 2010 00:06
Don't put the ' < around the field name, you don't do that in php, i can't see why it would be any different in dbpro

Mugen Wizardry
User Banned
Posted: 14th Nov 2010 00:07
well the thing is. i don't know why its acting up.

feel free to look at the WHERE clause and tell me why ^^

Thanks everyone! ^^

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 14th Nov 2010 00:29
Have you tried without the apostrophes? I'm fairly certain that's not correct syntax.

Mugen Wizardry
User Banned
Posted: 14th Nov 2010 01:03
yea, thats without the chr$(34)

i thought i mentioned that ^^

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 14th Nov 2010 01:24
chr$(34) is " not '.

I don't know if it's me not making sense, or if i've just totally got the wrong end of the stick here, it's late. I'll take a look tomorrow haha

Mugen Wizardry
User Banned
Posted: 14th Nov 2010 01:40
It's u, lol.

those quotes are there so it looks like this:

SELECT user and pwd FROM usertable WHERE user="username" AND pwd="password"

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Mugen Wizardry
User Banned
Posted: 14th Nov 2010 02:29
And please, if you have to talk in code, explain your reasoning for why you chose that certain variable, or w/e u do

Thank u! ^^

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 14th Nov 2010 14:35
After some googling, the second error shows that the query was carried out, but there was no result, and you are trying to apply that result to a variable, which obviously isn't possible.

Mugen Wizardry
User Banned
Posted: 14th Nov 2010 15:51
Ok, well how would I fix that?

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 14th Nov 2010 16:41
Try printing the query and see if it's what you want, put the query into the mysql workbench, see if it returns anything?

Mugen Wizardry
User Banned
Posted: 14th Nov 2010 16:44
i already did. it's returning what i want.

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 14th Nov 2010 19:32
I'm assuming you're not using a database plugin because you don't have local access to the MySQL server, thus you have to access it through php?

Mugen Wizardry
User Banned
Posted: 14th Nov 2010 20:53
Incorrect. I am using CattleRustler's plugin as I explained earlier. The PHP was a reference to what I'm trying to do to fix the error.

Now can someone please help me?

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 14th Nov 2010 21:03
surely the host should be localhost?

Mugen Wizardry
User Banned
Posted: 14th Nov 2010 21:10
I changed it so you can't see my real information

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 14th Nov 2010 22:27
If you have printed the query your code is generating and pasted that into MySQL workbench and it works, then try just that code in dbpro. (Connect & perform query) Post just that dbpro code and whether it works or not. The rest of your code is irrelevant to your problem and just confuses the issue.

So you should have something along the lines of:

Mugen Wizardry
User Banned
Posted: 14th Nov 2010 23:40 Edited at: 14th Nov 2010 23:41
here's the code i used to test:

dbc.php:



dbtest.php:



Here's what it returns:

SELECT user_name AND pwd FROM users WHERE user_name = user AND pwd = d41d8cd98f00b204e9800998ecf8427e

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 15th Nov 2010 04:37
Quote: "Incorrect. I am using CattleRustler's plugin as I explained earlier. The PHP was a reference to what I'm trying to do to fix the error."


Sorry, it was a long night with a sick dog and I must have missed that. Without really having time to dig to deep into this, here's what I saw off the top of my head.

Changing this,


To this should help for a start.


Rather than single quotes you were using the tilde, which I would think would certainly cause a database error. CHR$(34) is " which isn't going to help you much either, as the database driver is expecting single quotes.

Also, with CattleRustler's plugin there were really only two commands that I ever used to read data. MySQL_RunStatement, and MySQL_GetRowByColName. The RunStatement command returns the number of rows found (if any) so that's your error check to determine if you should try and read anything, and the other command of course to read the data. Remember too that rows returned start at index 0.

Those are really the only commands you need. Break it down and simplify, and it will make your life much easier when dealing with databases.

You might also try my database plugin DBConn.

Quote: " the above is based on THIS code to keep it from reading an empty string: "


This is unnecessary. If the row count returned by MySQL_RunStatement is 0, then there's nothing to read. So as long as you don't try and read it there's no error.

Hope that helps.

Mugen Wizardry
User Banned
Posted: 15th Nov 2010 15:01
Now it's returning a syntax error.

HOWEVER, it is NOT returning a 'There is no row at position 1'
error.

Here's the code:



I need to know how to fix this syntax error.

The warning is shown in the uploaded pic.

Thanks!

~Mugen~

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 15th Nov 2010 16:28
Quote: "Now it's returning a syntax error.

HOWEVER, it is NOT returning a 'There is no row at position 1'
error."


Don't relax yet, syntax errors are always identified first :p

Mugen Wizardry
User Banned
Posted: 15th Nov 2010 16:38
that doesn't help

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 15th Nov 2010 20:37 Edited at: 15th Nov 2010 20:38
In the error message it says,

for the right syntax to use near "users' WHERE

That first quote should be a single instead of a double.

Make sure you aren't putting any double quotes into tbl$ and you should be ok.

Mugen Wizardry
User Banned
Posted: 15th Nov 2010 21:45
i redid the query, and it's STILL giving me an error.

Which is your error because it was 2 single quotes for some reason.

as i redid the query:

renderquery$ = "SELECT "+"'"+colname$+"'"+" AND "+"'"+colname2$+"'"+" FROM "+"'"+tbl$+"'"+" WHERE "+"'"+colname$+"'"+" = "+"'"+X Get Widget Text$(user)+"'"+" AND "+"'"+colname2$+"'"+" = "+"'"+Hash MD5(X Get Widget Text$(pass))+"'"

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 16th Nov 2010 00:50
You need to get a better grip on your quote control. There is a LOT more there than is necessary.

The double quotes " designate where explicit strings are added to your string variable.

Single quotes ' should be the only quotes passed along to the SQL driver so that it knows when something is supposed to be a string and not a keyword.

I also noticed an SQL syntax error I hadn't before. There is no AND allowed when listing the columns you want selected. You just put a comma in between them. The AND keyword is only used after the WHERE clause.

This is what you want.


Which should give the output,

SELECT 'user', 'password' FROM 'users' WHERE 'username' = 'name' AND 'password' = 'yourpassword'

sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 16th Nov 2010 01:30
Plus you don't need to quote identifiers unless they have special characters or reserved words so:

SELECT user, password FROM users WHERE username = 'name' AND password = 'yourpassword';

would work as well and reads slightly easier. (To me anyway)

When debugging MySQL in dbpro I find logging is the best way to iron out long statements just because quotes, brackets etc are a nightmare when looking in the actual dbpro code. Just before you execute a sql statement, write the string out to a file (IanM's logging functions ideal) and then you can just paste that string into Workbench and test if it works. Cuts out 50% of the debugging straight away (ie. dbpro/mysql) and makes spotting syntax errors a lot easier.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 16th Nov 2010 02:29
Quote: "Plus you don't need to quote identifiers unless they have special characters or reserved words"


Good point.

Mugen Wizardry
User Banned
Posted: 16th Nov 2010 20:59 Edited at: 17th Nov 2010 02:06
KISTech, I have given up on this plugin.

HOWEVER, I have chosen to use yours.

Now since you know more about your plugin than anyone here, can u mind telling me why my program is crashing?

Also, I would like it to retrieve the md5 hash of the password, and the username only




EDIT: NVM

Fixed it!

For those of you who want to learn, I fixed the crash by adding this to the select DBR:

Case Default
DBR = DBConnect("DRIVER="+driver$+";SERVER="+connstr$(0)+";DATABASE="+connstr$(1)+";UID="+connstr$(2)+";PASSWORD="+connstr$(3)+";OPTION=3;Encrypt="+connstr$(4)+";")
EndCase

have fun!

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 17th Nov 2010 17:55
Glad it worked out.

Login to post a reply

Server time is: 2026-07-21 18:58:28
Your offset time is: 2026-07-21 18:58:28