Page 1 of 1
ELSE IN " DO WHILE LOOP "
Posted: Thu Sep 12, 2002 9:14 am
by Skywalker
What am I doing worng. I want to show a tekst when the account isn't in the database.
My script:
$Password = $_POST['Password'];
$Username = $_POST['Username'];
do {
If($Password == $row_Recordset1['Password'] && $Username == $row_Recordset1['Username']) {
echo ("Login gegevens zijn corect <META HTTP-EQUIV=\"refresh\" content=\"2;URL=admin-html.php\">\n"); }
else { echo ("Login is incorect <META HTTP-EQUIV=\"refresh" content=\"2;URL=login.php\">\n"); }
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
with out the bolt php line it works fine but with it, i doesn't do enything :/
[/b]
Posted: Thu Sep 12, 2002 9:22 am
by phice
Posted: Thu Sep 12, 2002 9:30 am
by Skywalker
I correct it, but when I am typing pass en username correct in, this appears
Login gegevens zijn niet correct Login gegevens zijn niet correct
and is sending me back to login.php insted to the admin-html.php
THIS TEXT: Login gegevens zijn niet correct Login gegevens zijn niet correct
must be seperated. It shows the tekst twice, because ther are two records in the table.
$Password = $_POST['Password'];
$Username = $_POST['Username'];
$Leeg1= 0;
do {
If($Password == $row_Recordset1['Password'] && $Username == $row_Recordset1['Username']) {
echo ("Login gegevens zijn corect <META HTTP-EQUIV=\"refresh\" content=\"2;URL=admin-html.php\"><br>\n"); }
else {
echo("Login gegevens zijn niet correct <META HTTP-EQUIV=\"refresh\" content=\"2;URL=login.php\">\n"); }
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
Posted: Thu Sep 12, 2002 9:47 am
by twigletmac
In your SQL statement put LIMIT 1 at the end and add your test for username and password, eg:
Code: Select all
$sql = "SELECT username, password FROM users WHERE username='".$_POSTї'username']."' AND password='".$_POSTї'password']."' LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
then only one record will be returned and you won't need the do...while loop but can test if the username and password are valid by doing:
Code: Select all
if (mysql_num_rows($result) == 1) {
echo "<p>Login gegevens zijn corect</p> <META HTTP-EQUIV="refresh" content="2;URL=admin-html.php">\n";
} else {
echo "<p>Login is incorect</p> <META HTTP-EQUIV="refresh" content="2;URL=login.php">\n";
}
Also, have you encrypted the password in the database? If so you'll need to encrypt the posted password in order to compare it with what's in the database.
Mac
Posted: Fri Sep 13, 2002 4:56 am
by Skywalker
It still doesn't work correct. It still doesn't read the second record in the table.
And it shows both texts when login is faild and correct. It shows everytime both texts.
This is my full script:
<?php require_once('../Connections/Verbinding.php'); ?>
<?php
mysql_select_db($database_Verbinding, $Verbinding);
$query_Recordset1 = "SELECT * FROM user";
$Recordset1 = mysql_query($query_Recordset1, $Verbinding) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$sql = "SELECT username, password FROM user WHERE username='".$_POST['username']."' AND password='".$_POST['password']."' LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) == 1) {
echo "<p>Login gegevens zijn corect</p> <META HTTP-EQUIV=\"refresh\" content=\"2;URL=admin-html.php\">\n";
} else {
echo "<p>Login is incorect</p> <META HTTP-EQUIV=\"refresh\" content=\"2;URL=login.php\">\n";
}
/*
$Password = $_POST['Password'];
$Username = $_POST['Username'];
$Leeg1= 0;
do {
If($Password == $row_Recordset1['Password'] && $Username == $row_Recordset1['Username']) {
echo ("Login gegevens zijn corect <META HTTP-EQUIV=\"refresh\" content=\"2;URL=admin-html.php\"><br>\n"); }
else {
echo("Login gegevens zijn niet correct <META HTTP-EQUIV=\"refresh\" content=\"2;URL=login.php\">\n"); }
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
*/
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Posted: Fri Sep 13, 2002 5:01 am
by twigletmac
Have you encrypted the password in the database? If so you'll need to encrypt the posted password in order to compare it with what's in the database.
Mac
Posted: Fri Sep 13, 2002 5:02 am
by Skywalker
No, because it beeing used only on the local network. It works fine, but it reads only the first record and not all of them, and both texts are been showed everytime, that is the only thing.
Posted: Fri Sep 13, 2002 4:35 pm
by Takuma
What happens if you do:-
Code: Select all
&lt;?php
$sql = "SELECT username, password FROM user WHERE username='".$_POSTї'username']."' AND password='".$_POSTї'password']."' LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
echo mysql_num_rows($result);
?&gt;