Have a problem with a while function !!!!!!!!!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
maceved23
Forum Newbie
Posts: 17
Joined: Sun Jul 13, 2003 11:56 pm

Have a problem with a while function !!!!!!!!!

Post by maceved23 »

Now I’m creating a code to query a DB. The DB is working fine and my query to, but I use a while statement in my code to search by email my DB, is the user exists, the message :

echo"<h2>User information</h2><br>";

echo"<b>$nombre $apellido1 $apellido2</b><br>";
is show.

If not the message :

echo"This email is not in DB!!!";

THE COMPLETE CODE IS:
<?php
include('config.php');

db_connect();
viewheader();

$email5=$email_busca;

$sql = "SELECT * FROM $dbtable";
$resultat = mysql_db_query($dbname, $sql);

if(empty($debut)) $debut = 0;
$nb_total=mysql_num_rows($resultat);

$sql = "SELECT * FROM $dbtable ORDER BY username ASC limit $debut, $max";
$resultat = mysql_db_query($dbname, $sql);
$nbenr = mysql_num_rows($resultat);



while ($profil = mysql_fetch_array($resultat))
{
$myid = ($profil["id"]);
$username = ($profil["username"]);
$nombre = ($profil["nombre"]);
$apellido1 = ($profil["apellido1"]);
$apellido2 = ($profil["apellido2"]);


if (($email1)== ($email5))
{
echo"<h2>User information</h2><br>";
echo"<b>$nombre $apellido1 $apellido2</b><br>";

}
else
echo"This email is not in DB!!!";
}

@mysql_close($db);


?>



The problem is when the user exists the information of my user is show but also 6 times the message This email is not in DB!!!.

I have six records at this moment in my DB this is why the message is show six times.

But is the email is not valid the message This email is not in DB!!! is show six times.

I already use the exit; to end the while but if I use It for a invalid email no message is show.

NEED HELP TO FINISH MY PROYECT
THANKS .
MARIO
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

I cant see that you declared $email1 anywhere, hence

Code: Select all

<?php
if (($email1)== ($email5)) 
?>
will allway return false, and your echo goes out...
Post Reply