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
https://forums.phpfreaks.com/topic/184085-if-else-problem/
Share on other sites

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

 

Not explaining what your script is supposed to doing

Not explaining what the problem is

Not posting just the relevant code

Writing like a 5 year old.

I'm sure I can think of other things you did wrong if I try really hard.

Link to comment
https://forums.phpfreaks.com/topic/184085-if-else-problem/#findComment-971868
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.