Jump to content

if else problem


chanfuterboy

Recommended Posts

hi, chek the code below and tell my pls what im doind wrong.

 

<?php
include("dbconfig.php");

//session_start();



// we must never forget to start the session
//session_start(); 

if (isset($_POST['username']) && isset($_POST['password'])) {
     	
$username = $_POST['username'];
$usernameEnc = md5($username);
$password = md5($_POST['password']);

require_once("dbconfig.php");

// check if the user id and password combination exist in database
$query = "SELECT *
           FROM users
           WHERE usernameEnc = '$usernameEnc' 
                 AND password = '$password'";

$row = mysql_query($query) or die ("Error - Couldn't login user.");

if (mysql_num_rows($row) == 1) {
	// the user id and password match,
	// set the session
	$_SESSION['username'] = $row['username'];
	$array = mysql_fetch_assoc($row);
	$_SESSION['username'] = $array['username'];


	// after login we move to the main page
	echo "Welcome $username! You've been successfully logged in.";
	echo"<p><img src='images/loading.gif'></p>";
	echo "<META HTTP-EQUIV=\"Refresh\" Content=\"2; URL=members.php?user=$usernameEnc&pass=$password\">";
	exit();

} else // bad info.
{
	echo "Error - Couldn't login user.<br /><br />
	   Please try again.";
	echo"<p><img src='images/loading.gif'></p>";
	echo "<META HTTP-EQUIV=\"Refresh\" Content=\"1; URL=index.php\">";
	exit();
}

}
?>

<?php 

if ($_GET['user']&&$_GET['pass']) {
$password = $_GET['pass'];
$username = $_GET['user'];
$query = "SELECT username
           FROM users
           WHERE usernameEnc = '$username' 
                 AND password = '$password'";
$row = mysql_query($query) or die ("Error - Couldn't login user.");
if (mysql_num_rows($row) == 1) {
	$array = mysql_fetch_assoc($row);
	$user = $array['username'];
	echo "<table style=\"padding-left:70px; padding-right:5px;\" width=\"100%\"><tr><td><p>Welcome, $user</p></td><td align=\"right\">";
	include('menu.php');
	echo "</td></tr></table>";
} else {
	echo "Error - Couldn't login user.<br /><br />
	   Please try again.";
	echo"<p><img src='images/loading.gif'></p>";
	echo "<META HTTP-EQUIV=\"Refresh\" Content=\"1; URL=index.php\">";
	exit();
}	
}

else
{

?>


<table width="100%"><tr><td style="padding-left:20px;"><a href="online.php">Online members</a>   <a href="register.php">
		Registra</a>   <a href="recoverpass.php">
		Forgot password?</a></td><td align="right">

		<?php if($_SESSION['id'])
{
    
echo "     Welcome, ".$_SESSION['username'];

}

else
{
?>
   <form action="login.php" method="post">


				 <p align="right"><label><b>Username:</b> <input type="text" name="username" size="10" value="<?php echo $username; ?>"></label>  


				 <label><b>Password:</b> <input type="password" name="password" size="10" value="" /></label>


				 <input type="submit" value="Login!">

	</p>


	</form>
	</td></tr></table>            
<?php
}
?>





Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.