incredibale3 Posted September 16, 2008 Share Posted September 16, 2008 Whenever I try out my login system it has this problem: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\Hosting\3156647\html\Login.php on line 21The email address was not found.Notably, it's probably fixable by just using a different argument, but i'm pretty new to php, so I could use some help. And yes, the login system i'm trying to get to work is based off of the pinned topic on this section of the forums. Here's the code in question: $result = db_query("SELECT id, name, password FROM users WHERE email='" . mysql_real_escape_string($email) . "'"); if (!($row = mysql_fetch_assoc($result))) $error_string .= 'The email address was not found.<br>';I could use some advice please Link to comment Share on other sites More sharing options...
justsomeguy Posted September 16, 2008 Share Posted September 16, 2008 The error means the query is failing. Use mysql_error to find out why. Open the db.php file and find the db_query function and change it to be like this: function db_query($sql){ return mysql_query($sql, $GLOBALS['con']) or die (mysql_error());} Link to comment Share on other sites More sharing options...
incredibale3 Posted September 16, 2008 Author Share Posted September 16, 2008 Now it just says No Database Selected, which is weird because I have everything set up so it should connect to the right database...<?php$con = mysql_connect('10.6.186.65', 'PlayerDataInfo', 'FakePass'); // host, username, passwordmysql_select_db('w3', $con);function db_query($sql){ return mysql_query($sql, $GLOBALS['con']) or die (mysql_error());}?> Link to comment Share on other sites More sharing options...
justsomeguy Posted September 16, 2008 Share Posted September 16, 2008 Use mysql_error on the other statements too. In retrospect I should have included mysql_error in the original thread.mysql_select_db('w3', $con) or die (mysql_error()); Link to comment Share on other sites More sharing options...
incredibale3 Posted September 16, 2008 Author Share Posted September 16, 2008 Now whenever I try to open up the login page it goes: Access denied for user 'PlayerDataInfo'@'%' to database 'w3' Link to comment Share on other sites More sharing options...
justsomeguy Posted September 16, 2008 Share Posted September 16, 2008 Apparently they aren't. You need to give that user access to the database, if you log in to phpMyAdmin you can click Privileges to set up users. If you don't have phpMyAdmin set up you'll need to use the MySQL command line. Link to comment Share on other sites More sharing options...
incredibale3 Posted September 16, 2008 Author Share Posted September 16, 2008 I don't see where it says privlages, although i came across an interesting process..ID User Host Database Command Time Status SQL queryKill 5749446 PlayerDataInfo 68.178.254.44:59651 None Query 0 --- SHOW PROCESSLIST Link to comment Share on other sites More sharing options...
justsomeguy Posted September 16, 2008 Share Posted September 16, 2008 That process is you asking for the process list (the SHOW PROCESSLIST command). Link to comment Share on other sites More sharing options...
incredibale3 Posted September 16, 2008 Author Share Posted September 16, 2008 Hmm. Well, since i can't find privileges, how would I go about inserting it in SQL? Link to comment Share on other sites More sharing options...
justsomeguy Posted September 16, 2008 Share Posted September 16, 2008 You'll need to open the MySQL command line and use a GRANT statement.http://dev.mysql.com/doc/refman/5.0/en/grant.html Link to comment Share on other sites More sharing options...
incredibale3 Posted September 16, 2008 Author Share Posted September 16, 2008 So something likeGRANT ALL ON PlayerDataInfo.Mysql TO 'PlayerDataInfo'@'%'; ? Link to comment Share on other sites More sharing options...
justsomeguy Posted September 16, 2008 Share Posted September 16, 2008 Something like that. It will probably be @localhost Link to comment Share on other sites More sharing options...
incredibale3 Posted September 16, 2008 Author Share Posted September 16, 2008 Hmm, now I seem to have another issue:ErrorSQL query:GRANT ALL ON PlayerDataInfo.Mysql TO 'PlayerDataInfo'@'localhost';MySQL said: Documentation#1142 - GRANT,REFERENCES command denied to user 'PlayerDataInfo'@'68.178.254.44' for table 'Mysql' Link to comment Share on other sites More sharing options...
justsomeguy Posted September 16, 2008 Share Posted September 16, 2008 It looks like your database is called w3, not PlayerDataInfo (at least that's what was in the mysql_select_db function). You probably want this:GRANT ALL ON w3.* TO 'PlayerDataInfo'@'localhost'; Link to comment Share on other sites More sharing options...
incredibale3 Posted September 16, 2008 Author Share Posted September 16, 2008 Actually, the only reason i have it as w3 is because the login thing at the top said so. *goes to change*edit: now that I fixed the w3 thing it says this again even tho the or die part is still there:Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\Hosting\3156647\html\Login.php on line 21The email address was not found. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 16, 2008 Share Posted September 16, 2008 The db_query function should be outputting an error message if the query failed, are you not seeing something like that? You can also try to print the query that you're trying to run and run it directly on phpMyAdmin. Also add the mysql_error output to the mysql_connect function too, that might also be failing if the username or password is wrong. Link to comment Share on other sites More sharing options...
incredibale3 Posted September 16, 2008 Author Share Posted September 16, 2008 Adding it didn't change anything, and no, i'm not seeing anything saying the query failed, and this is the output from running it directlyErrorMySQL said: Documentation#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<?php$con = mysql_connect('10.6.186.65', 'PlayerDataInfo', 'Password') or ' at line 1 Link to comment Share on other sites More sharing options...
justsomeguy Posted September 16, 2008 Share Posted September 16, 2008 Don't paste the PHP code in to phpMyAdmin, just the SQL query. phpMyAdmin doesn't execute PHP code. You're running this query:$result = db_query("SELECT id, name, password FROM users WHERE email='" . mysql_real_escape_string($email) . "'");So print that query out, copy it, and paste it into phpMyAdmin to run in the SQL box.echo "SELECT id, name, password FROM users WHERE email='" . mysql_real_escape_string($email) . "'";Put that line before you run the query so it prints it out before it executes it. If the query itself doesn't give an error, which it shouldn't, then it's still a connection problem. So the db.php file should look like this: <?php$con = mysql_connect('10.6.186.65', 'PlayerDataInfo', 'FakePass') or die (mysql_error()); // host, username, passwordmysql_select_db('w3', $con) or die (mysql_error());function db_query($sql){ return mysql_query($sql, $GLOBALS['con']) or die (mysql_error());}?> Link to comment Share on other sites More sharing options...
incredibale3 Posted September 17, 2008 Author Share Posted September 17, 2008 Yes, except replace the w3 with PlayerDataInfo..And also, this is the response: ErrorSQL query: Documentationecho "SELECT id, name, password FROM users WHERE email='".mysql_real_escape_string($email). "'"MySQL said: Documentation#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'echo "SELECT id, name, password FROM users WHERE email='" . mysql_real_escape_st' at line 1 And this is the other lines response:ErrorSQL query: Documentationecho "SELECT id, name, password FROM users WHERE email='".mysql_real_escape_string($email). "'"MySQL said: Documentation#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'echo "SELECT id, name, password FROM users WHERE email='" . mysql_real_escape_st' at line 1 Link to comment Share on other sites More sharing options...
justsomeguy Posted September 17, 2008 Share Posted September 17, 2008 You're still pasting PHP code into the SQL box.I assume this is the login page you're working on, so you have code in the login page that looks like this: $result = db_query("SELECT id, name, password FROM users WHERE email='" . mysql_real_escape_string($email) . "'"); if (!($row = mysql_fetch_assoc($result))) $error_string .= 'The email address was not found.<br>'; What you need to do is add that line of code before the query gets executed: echo "SELECT id, name, password FROM users WHERE email='" . mysql_real_escape_string($email) . "'"; $result = db_query("SELECT id, name, password FROM users WHERE email='" . mysql_real_escape_string($email) . "'"); if (!($row = mysql_fetch_assoc($result))) $error_string .= 'The email address was not found.<br>'; Now you need to go through the login in the browser. When it runs that code you should see it print the SQL query out in the browser, along with whatever other error messages you were getting. You need to copy the query that it printed and paste that into phpMyAdmin to execute. You can only give phpMyAdmin SQL code to execute, it will not execute PHP code that you paste in. Link to comment Share on other sites More sharing options...
incredibale3 Posted September 17, 2008 Author Share Posted September 17, 2008 Weird, look at what happened:Showing rows 0 - 1 (2 total, Query took 0.0008 sec)SQL query: SELECT id, name,PASSWORD FROM usersWHERE email = 'incredibale3@gmail.com'LIMIT 0 , 30But then, it gets weirder, it made a new account and kept my old one.Full Texts id name password Edit Delete 1 J password Edit Delete 3 J 3c08f43130520a6477ed790a91dfa86f9676b251I think this is a connection error, because now that i check the register system won't work either... and since this query worked in finding the email, it shouldn't be the query's fault. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 17, 2008 Share Posted September 17, 2008 I don't think there's a problem with the query either, I think either the username, password, or database name is wrong or the user doesn't have access to the database. Link to comment Share on other sites More sharing options...
incredibale3 Posted September 17, 2008 Author Share Posted September 17, 2008 This is very instresting, my friend registered and it kind of worked. The only flaw is it morphed his password like it did to mine, and it won't take people to thankyou.php, it tried to take them to warnations.net/register.php/thankyou.php because the registering system is having a problem. Maybe it's something in the code... Are you sure nothing's wrong with the Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\Hosting\3156647\html\Login.php on line 22? Maybe it's coded wrong.. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 17, 2008 Share Posted September 17, 2008 Yes, I'm sure that the code I originally posted in the pinned topic works correctly, I was running it as I posted that topic. The code isn't very complex, there's not a lot that can break. Link to comment Share on other sites More sharing options...
incredibale3 Posted September 17, 2008 Author Share Posted September 17, 2008 Well, maybe it's because the database has the same name as the login username? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.