Hello everyone,
I need help about making a log in form with PHP/HTML and MYSQL. I’ll first show you my HTML page:
[code]
Turisticka Agencija<h1>Unesite vase podatke za logovanje u sistem</h1>
<body>
<form action="proveriLogin.php" method="post">
<p>
<table>
<tr>
<td> Korisnicko ime:</td><td><input type="textbox" name="korisnickoIme"/></td>
</tr>
<tr>
<td> Lozinka:</td><td><input type ="password" name="lozinka"/></td>
</tr>
</table>
</p>
<p>
<input type="submit" value="Uloguj se"/>
</p>
</form>
[/code]
As you can see its pretty simple log in where “Korisnicko ime” is Username and “lozinka” a password, with button to log in. Now
my problem is that i have a MYSQL table named “sluzbenik” which is where register users are, and i have only 2 users /rows in
that table. Now when i try to compare if username and password are correct and i do this:
[php] while ($row = mysql_fetch_array($result)) {
if (($KorisnickoIme == $row[‘Korisnicko Ime’]) && ($Lozinka == $row[‘Lozinka’])) {
echo “Uspesno ste se ulogovali”; // Success message
}[/php]
it works very fine and thats okey, i check both user names and both passwords diffrently and how they should go together and it
works, and thats fine. But, when i want to compare if those two are NOT the same and i create another IF like this:
[php] if (!($KorisnickoIme == $row[‘Korisnicko Ime’]) || !($Lozinka == $row[‘Lozinka’])) {
echo “Uneli ste pogresne podatke”;
break;
}
}[/php]
so that my whole WHILE looks like this :
[php]
while ($row = mysql_fetch_array($result)) {
if (($KorisnickoIme == $row[‘Korisnicko Ime’]) && ($Lozinka == $row[‘Lozinka’])) {
echo “Uspesno ste se ulogovali”; // Success log in
}
if (!($KorisnickoIme == $row['Korisnicko Ime']) || !($Lozinka == $row['Lozinka'])) {
echo "Uneli ste pogresne podatke"; // Wrong info
break;
}
}[/php]
For the first user that is in table it works great, when i check the next user, or in my case the 2nd in the table user, i
would always get either both messages that i placed echo in first IF where is success message and 2nd echo in second IF where
is a message if u typed wrong info. Now if i place break; like i did there, i will remove getting 2 messages but i will always
get the message about wrong info even thou i enter the right info, and its only with the 2nd user or last in MYSQL table. I
can’t really see why is it doing that.
I am not sure if there is some more better or more simple way to do this. Or if i am not doing something right.
I’d appriciate any help i could get.
Thanks,
Dusan Acimovic