Page 1 of 1

Not a valid MySQL resource...

Posted: Sat May 11, 2002 5:13 pm
by Jim
Warning: Supplied argument is not a valid MySQL result resource in /home/maxxxtor/public_html/clanmanager/login.php on line 23

Here's the code:

Code: Select all

<FORM METHOD=POST ACTION=login.php>
<TABLE>
<TR>
<TD>Username</TD><TD><input type=text name=name></TD>
<TR>
<TD>Pass</TD><TD><input type=text name=pass></TD>
<TR>
<TD><input type=submit value=submit></TD>
</TR>
</TABLE>
</FORM>



<?
if($name)&#123;

ob_start();
include("config.php");

$sql = "SELECT from cm_admin id WHERE name='.$name.' and pwd='.$pass.'";
$query = mysql_query($sql);
$num = mysql_numrows($query);

if($num == 1) &#123;

echo 'You are logged in!!!';

setcookie("prodigy_name" , '.$name.');
setcookie("prodigy_pass" , '.$pass.');

&#125; else &#123;

print("Your Username and/or Password are incorrect.  If you feel you have reached this message in error, please contact the <a href='mailto:jim@strategyplanet.com'>webmaster</a>.");

&#125;

&#125;

?>
Thanks for the help!

Posted: Sat May 11, 2002 6:16 pm
by gotDNS
I'm not sure, Jim but shouldn't:

Code: Select all

$sql = "SELECT from cm_admin id WHERE name='.$name.' and pwd='.$pass.'";
actually be

Code: Select all

$mysql = "SELECT from cm_admin id WHERE name='.$name.' and pwd='.$pass.'";
The $mysql = "SELECT...

opps, forgot

Posted: Sat May 11, 2002 6:18 pm
by gotDNS
oops, forgot something:

Shouldn't you have:

Code: Select all

SELECT * from ......
rather than:

Code: Select all

SELECT from ...
I usually have the * there, but it could just specify one portion of the DB.

Posted: Sat May 11, 2002 7:28 pm
by mydimension
yeah, its got to have a * in there or a list of fields that you wish to select

Re: Not a valid MySQL resource...

Posted: Sun May 12, 2002 4:18 am
by twigletmac
Jim wrote:Warning: Supplied argument is not a valid MySQL result resource in /home/maxxxtor/public_html/clanmanager/login.php on line 23
This means that your query has a problem with it, or you were unable to connect to the mysql server or database.

Try putting:

Code: Select all

echo mysql_error();
after the query line and it should give you more information.
gotDNS wrote:The $mysql = "SELECT...
FWIW $sql was just a variable, changing it to $mysql would have made no difference whatsoever (just would have meant a new variable name) :).

Mac

Posted: Sun May 12, 2002 9:13 pm
by sam
It is not going to give you an error because that is a valid SQL statement. The problem you have is in the WHERE clause.

Code: Select all

WHERE name='.$name.' and pwd='.$pass.'";
You have it searching for name equaling .$name. and pass equaling .$pass. You have to add "s in there if your going to step out of the srting and add another string.

Code: Select all

WHERE name='".$name."' and pwd='".$pass."'";
Cheers Sam

sql

Posted: Mon May 13, 2002 1:14 am
by prasadharischandra
the sql start fro
SELECT *
you missed * part

Posted: Mon May 13, 2002 2:42 am
by twigletmac
sam wrote:It is not going to give you an error because that is a valid SQL statement.
It is going to give an error because nothing was specified between the SELECT keyword and the FROM keyword. The error that it would show is:

Code: Select all

You have an error in your SQL syntax near 'FROM users id WHERE username='.$name.' and password='.$pass.' LIMIT 0, 500' at line 1
or something similar.

The mistake with the WHERE clause would have just caused no rows to be returned because it wouldn't have matched anything in the database. Then what would have been displayed is Jim's predefined error message about incorrect username or password.

Mac

PS. If you're having problems with a MySQL query in PHP first try echoing the SQL statement to the screen so you can spot errors like the one's with .$name. and .$pass.. If that seems fine try running it through MySQL by the command line or a GUI like phpMyAdmin to see if it is a problem with the SQL statement or your PHP code.

Re: Not a valid MySQL resource...

Posted: Mon May 13, 2002 7:44 am
by mikeq
Jim wrote:Warning: Supplied argument is not a valid MySQL result resource in /home/maxxxtor/public_html/clanmanager/login.php on line 23

Here's the code:

Code: Select all

$sql = "SELECT * from cm_admin id WHERE name='.$name.' and pwd='.$pass.'";
The problem is the .'s in your SQL statement, you don't need to concatenate the variables in there, try this

Code: Select all

$sql = "SELECT * from cm_admin id WHERE name='$name' and pwd='$pass'";
Because you are in " then PHP will put in the values of $name and $pass without any further work.

Mike