PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Jim
Forum Contributor
Posts: 238 Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas
Post
by Jim » Sat May 11, 2002 5:13 pm
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){
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) {
echo 'You are logged in!!!';
setcookie("prodigy_name" , '.$name.');
setcookie("prodigy_pass" , '.$pass.');
} else {
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>.");
}
}
?>
Thanks for the help!
gotDNS
Forum Contributor
Posts: 217 Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA
Post
by gotDNS » Sat May 11, 2002 6:16 pm
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 $
my sql = "SELECT...
gotDNS
Forum Contributor
Posts: 217 Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA
Post
by gotDNS » Sat May 11, 2002 6:18 pm
oops, forgot something:
Shouldn't you have:
rather than:
I usually have the * there, but it could just specify one portion of the DB.
mydimension
Moderator
Posts: 531 Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:
Post
by mydimension » Sat May 11, 2002 7:28 pm
yeah, its got to have a * in there or a list of fields that you wish to select
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Sun May 12, 2002 4:18 am
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:
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
sam
Forum Contributor
Posts: 217 Joined: Thu Apr 18, 2002 11:11 pm
Location: Northern California
Contact:
Post
by sam » Sun May 12, 2002 9:13 pm
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
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Mon May 13, 2002 2:42 am
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.
mikeq
Forum Regular
Posts: 512 Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland
Post
by mikeq » Mon May 13, 2002 7:44 am
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