Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

PHP Login


ghost's Avatar
0 0

I'm trying to code a login for my site. It is an odd registration message whereby the register script send me an e-mail to check before I manually add the user to the database. I am having problems with mysql_result(). This is my login code:

<?
$user=$_POST['username'];
$pass=$_POST['password'];
$encpass=md5($pass);

$mysqluser="mastergamer";
$mysqlpass="pass hidden";
$dbase="mastergamer";
mysql_connect(localhost, $user, $pass);
@mysql_select_db($dbase) or die( "Unable to select database");
$query="SELECT * FROM `users` WHERE user='$user' and pass='$encpass'";
$result=mysql_query($query);


$returneduser=mysql_result($result, "username");
$returnedpass=mysql_result($result, "password");
$returnedmail=mysql_result($result, "email");
 
mysql_close();

if($user==$returneduser && $encpass==$returnedpass)
{
echo "Now logged in as $user";
} else {
echo "Login error, please try again";
}
?>

I keep getting this error:

Warning: mysql_result(): supplied argument is not a valid MySQL result resource.

What do I need to change in mysql_result() i order for it to work?


ghost's Avatar
0 0

I would advise using mysql_fetch_array it works loads better.


ghost's Avatar
0 0
$user=$_POST['username'];
$pass=$_POST['password'];
$encpass=md5($pass);

$mysqluser="mastergamer";
$mysqlpass="pass hidden";
$dbase="mastergamer";
mysql_connect(localhost, $user, $pass);
@mysql_select_db($dbase) or die( "Unable to select database");
$query="SELECT * FROM `users` WHERE user='$user' and pass='$encpass'";
$result=mysql_query($query);
$row=mysql_fetch_array($result);

$returneduser=($row['user']);
$returnedpass=($row['pass']);
$returnedmail=($row['email']);

mysql_close();

if($user==$returneduser && $encpass==$returnedpass)
{
echo "Now logged in as $user";
} else {
echo "Login error, please try again";
}
?>

Another thought, could it be that you are using "username" rather than "user"???


ghost's Avatar
0 0

I changed the code to:

<?
$user=$_POST['username'];
$pass=$_POST['password'];
$encpass=md5($pass);

$mysqluser="mastergamer";
$mysqlpass="hidden";
$dbase="mastergamer";
mysql_connect(localhost, $user, $pass);
@mysql_select_db($dbase) or die( "Unable to select database");
$query="SELECT * FROM `users` WHERE username='$user' and password='$encpass'";
$result=mysql_query($query);
$row=mysql_fetch_array($result);

$returneduser=mysql_result($row['username']);
$returnedpass=mysql_result($row['password']);
$returnedmail=mysql_result($row['email']);
 
mysql_close();

if($user==$returneduser && $encpass==$returnedpass)
{
echo "Now logged in as $user";
} else {
echo "Login error, please try again";
}
?>

and now it gives me the error:

markupWrong parameter count for mysql_result()

EDIT: Fixed it now, I changed $returneduser=mysql_result($row['username']); to $returneduser=mysql_result($result,0,username); and now it works.

Thanks for your help :)


SySTeM's Avatar
-=[TheOutlaw]=-
20 0

Hehe, I exploited your register page :p:p:p


ghost's Avatar
0 0

Yes you did, but I patched that by only letting the same IP register once per hour.


SySTeM's Avatar
-=[TheOutlaw]=-
20 0

hehehe thanks god for cURL!


ghost's Avatar
0 0

Yeah, that cURL is cool, I'm defiently going to learn that now :p


ghost's Avatar
0 0

Yer, unfortunately my server doesn't have it.

Do you know any which do?


ghost's Avatar
0 0

Here is a list from cURL's official website

*  classicwebdevelopment.com phpinfo
* dreamhost.com
* flexwebhosting.nl
* fuitadnet.com
* godaddy.com
* henselhosting.com
* hostgator.com
* hytekhosting.com
* iquesthosting.com
* lunarpages.com
* lypha.com
* netvigour.com
* oneandone.co.uk
* schogini.com
* streamservice.nl

but I'm not too sure about free ones:D