hellboy012 Posted May 12, 2011 Share Posted May 12, 2011 Here is the code: <html> <head> <title>Login</title> </head> <body> <form action="" method="post"> Nick: <br /> <input type="text" name="nick" /> <br /> Pass: <br /> <input type="password" name="pass" /> <br /> <input type="submit" name="uloguj_se" value="Login" /> <? if(isset($_POST['uloguj_se'])){ include("connect.php"); $nick = $_POST['nick']; $pass = $_POST['pass']; $nickdva = mysql_query("SELECT * FROM klijenti WHERE nick='$nick'"); $passdva = mysql_query("SELECT * FROM klijenti WHERE password='$pass'"); if($nick==$nickdva && $pass==$passdva) { echo "<center>Poz! </center>"; } else { echo "<center>Netacan username/pw.</center>"; } echo "</form>"; echo "</body>"; echo "</html>"; } ?> Link to comment https://forums.phpfreaks.com/topic/236161-login-dont-work/ Share on other sites More sharing options...
phppaper Posted May 12, 2011 Share Posted May 12, 2011 if(isset($_POST['uloguj_se'])) <- wont work, its just the button's name. Wont work (you are check 2 different things): $nickdva = mysql_query("SELECT * FROM klijenti WHERE nick='$nick'"); $passdva = mysql_query("SELECT * FROM klijenti WHERE password='$pass'"); should be: $nickdva = mysql_query("SELECT * FROM klijenti WHERE nick='$nick' and password='$pass'"); the rest you could develop. Link to comment https://forums.phpfreaks.com/topic/236161-login-dont-work/#findComment-1214225 Share on other sites More sharing options...
JasonLewis Posted May 12, 2011 Share Posted May 12, 2011 if(isset($_POST['uloguj_se'])) <- wont work, its just the button's name. Using the button name there is fine, upon pressing the submit button it sets the buttons name as a key and its value as a value in the $_POST array, thus using this allows you to determine if your form has been submitted. hellboy012, you can change your code to how phppaper suggested, with the single query. However checking a variable against a mysql_query() returned value will achieve nothing. mysql_query() returns a MySQL resource, which is totally useless for what you want. You'll need to take it a bit further and determine if there are any rows, with mysql_num_rows. $query = mysql_query("SELECT * FROM klijenti WHERE nick='$nick' AND password='$pass'"); if(mysql_num_rows($query) == 0){ echo '<center>Netacan username/pw.</center>'; }else{ echo '<center>Poz! </center>'; } Good luck. Link to comment https://forums.phpfreaks.com/topic/236161-login-dont-work/#findComment-1214380 Share on other sites More sharing options...
hellboy012 Posted May 12, 2011 Author Share Posted May 12, 2011 Thank you all! Link to comment https://forums.phpfreaks.com/topic/236161-login-dont-work/#findComment-1214601 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.