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!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
here is an example of my problem in story form
i made a starting account, example being pizza with the password atypeoffood
i make a new account, totally different password
the password for the new account doesn't work, but when i try to put in the password for pizza account into the new account, it works.
what is the problem?
heres an example of what i'm using.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
could i see an example? i am still having trouble getting it to work
EDIT: nevermind, i got it to work after a little bit of trial and error, plus i looked at the php.net site which helped a small bit.
if(isset($_POST['login'])){
$username=$_POST['username'];
$password = md5($_POST['password']);
$h=mysql_query("SELECT password FROM users WHERE username='$username' AND password='$password'");
if(mysql_num_rows($h) == 1){
setcookie("etrin_username",$_POST['username'],time()+60*60*24*365);
setcookie("etrin_password",$_POST['password'],time()+60*60*24*365);
echo"<meta http-equiv=\"Refresh\" content=\"3;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
}
else{
echo('Oh dear. It would appear you entered an incorrect password.');
}
}
Shouldnt the "username" field in the query also be selected along with the password field? I've had that problem many times, so I usually just select all (*)
E.g.
apoltix wrote:Shouldnt the "username" field in the query also be selected along with the password field? I've had that problem many times, so I usually just select all (*)
Why would you want to select a username if you already know it? It's not like it's going to change somewhere...
Are you aware that 'SELECT ALL' and 'SELECT *' mean different things?
SELECT COUNT(primary_key_column) AS count FROM users WHERE username='$username' AND password='$password'
When the count is >= 1 (are there situations where it can be > 1 ?) i know that there is (atleast) one account with the same username and password and thus the credentials are valid...