Fix my SQL [800 Credits]

btfog

New Member
Messages
118
Reaction score
2
Points
0
Can figure out what is wrong. Keep getting this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource... on line 12. I'll test the code in order of the replies, and first correct person gets the credits. Here is the code:
PHP:
<?
include("connection.php");
$username=trim($username);
$password=trim($lpassword);
if($username=="" || $password =="")
{
	header("Location: index.php?error=wu");
	exit;
}
$sql="SELECT 'password' FROM 'admin' WHERE 'username'='$username'";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
	$dbpass=$row[0];
}
if($dbpass==$password)
{
	session_start();
	$admin_username=$username;
	session_register("admin_username");
}
else
{
	$myFile = "index.php?error=wu";
	$fh = fopen($myFile, 'w');
	exit;
}
?>
 

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
Wrap the 'password', 'admin' and 'username' with ` instead, like so:
$sql="SELECT `password` FROM `admin` WHERE `username`='$username'";
or remove the quotes completely:
$sql="SELECT password FROM admin WHERE username='$username'";
 
Last edited:

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
OK, try inserting mysql_error() like this and it'll tell you what is wrong with your SQL:
...
$sql="SELECT 'password' FROM 'admin' WHERE 'username'='$username'";
$result=mysql_query($sql);
echo mysql_error();
while($row=mysql_fetch_array($result))
...
 
Last edited:

btfog

New Member
Messages
118
Reaction score
2
Points
0
it is saying no database selected, however, that should have been achieved by my "connection.php"
 

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
Well clearly it hasn't, are you sure you are selecting a valid database?
 

btfog

New Member
Messages
118
Reaction score
2
Points
0
I'm obviously retarded... uploaded my connection file without making changes. Thanks... will sent credits when the system works again
 
Top