Forum Moderators: coopster
*************************************************
<?php
include("dbc1.php");//connects to database
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$myusername = strtr(mysql_real_escape_string('$myusername'),array('_' => '\_', '%' => '\%'));
$mypassword = strtr(mysql_real_escape_string('$mypassword'),array('_' => '\_', '%' => '\%'));
$sql=mysql_query("SELECT * FROM 'Registration' WHERE ('username'='$myusername') AND ('password'='md5($mypassword)')");
$count=mysql_num_rows($sql);
if($count==1){
$_SESSION['myusername']='myusername';
header("location:game.php");
}
else {
echo "Wrong Username or Password";
}
?>
*************************************************
errors
*************************************************
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a1606798/public_html/login.php on line 10
*************************************************
The data that is entered into the database when the user registers goes through strtr and real escape, and the passwords are submitted through md5() when entered into the query.
Through my trial and error, I think there is a problem with the query searching through the database...
It also returns that I have the Wrong Username or password. (and yes... i double and triple checked the name and passwords)
I've been working on this for a while, and i've asked some other people about it, but they couldn't figure it out. Even when we got the mysql errors to go away, it still said that the username/pass didn't work.
ANYTHING you can think of, please tell me.
I'm not really understanding why you're doing the translations on the strings but if that's the way they went in I don't think it's causing a problem. If you use the php md5() function you don't even need to do anything to the password.
This:
$sql=mysql_query("SELECT * FROM 'Registration' WHERE ('username'='$myusername') AND ('password'='md5($mypassword)')");
You can use backticks on field names, but I'm pretty sure you can't use single quotes, and the quotes on the password are in the wrong place - try this instead:
$sql=mysql_query("SELECT * FROM Registration WHERE (username='$myusername') AND (password=md5('$mypassword'))");
If that still doesn't work, add:
if(!$sql) echo mysql_error();
right after the line so you can see what it's complaining about.
Any ideas why it wouldn't work?
$_SESSION['myusername']='myusername';
header("location:game.php");
}
else {
echo "Wrong Username or Password";
}
?>
*********************************************
Thank you for your help. I'm sure i'll be back here later if i ever have more questions.