ELSE IN " DO WHILE LOOP "
Moderator: General Moderators
ELSE IN " DO WHILE LOOP "
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]
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]
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));
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));
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
In your SQL statement put LIMIT 1 at the end and add your test for username and password, eg:
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:
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
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());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";
}Mac
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);
?>
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);
?>
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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;