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>"; } ?> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
hellboy012 Posted May 12, 2011 Author Share Posted May 12, 2011 Thank you all! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.