Jump to content

I have a small problem


incredibale3

Recommended Posts

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...