Jump to content

[SOLVED] Quick Question


chocopi

Recommended Posts

okie dokie here is all of it:

 

I wrote it quite quickly so there is probably quite a few mistakes

 

<?php

// Login.php

// Database Connection
$con = mysql_connect ( $dbhost, $dbuser, $dbpass ) or
	die ("Could not connect: " .mysql_error());
mysql_select_db ($dbname) or
	die (mysql_error());

// Declare Variables
// User Defined
	$username = $_POST['username'];
	$raw_password = $_POST['password'];
// Automatic
	$title = 'Chocopi :: Login';
	$password = md5($raw_password);
	$last_login = date('d/m/y');
	$login = mysql_query("SELECT id FROM Mark WHERE username='$username' && password='$password'");
	$login_check = mysql_num_rows($login);
	$errors = 0;

// Html Code
print("<html> \n");
print("	<head> \n");
print("		<title>$title</title> \n");
print("	</head> \n");
print("<body> \n");
print("<form name=\"login\" method=\"post\" action=\"$PHP_SELF\"> \n");
print("<center> \n");
print("<table width=\"70%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"> \n");
print("	<th colspan=\"2\">Login</th> \n");
print("		<tr> \n");
print("			<td align=\"center\"> \n");
print("			Username: \n");
print("				<input type=\"text\" name=\"username\" value=\"$username\" maxlength=\"20\" /> \n");
print("			</td> \n");
print("		</tr> \n");
print("		<tr> \n");
print("			<td align=\"center\"> \n");
print("			Password:   \n");
print("				<input type=\"password\" name=\"password\" value=\"$raw_password\" maxlength=\"20\" /> \n");
print("			</td> \n");
print("		</tr> \n");
print("		<tr> \n");
print("			<td align=\"center\"> \n");
print("				<input type=\"submit\" name=\"submit\" value=\"Login\" /> \n");
print("			</td> \n");
print("		</tr> \n");
print("		<tr> \n");
print("			<td align=\"center\"> \n");
print("<font color=\"#ff0000\"> \n");

// Validation
if($_POST)
{
// Check username and password are correct
if ($login_check == 0)
{
	echo("Sorry, but your username and password combination is incorrect.");
	$errors++;
} else
	if ($login_check > 0)
	{
		print("</font> \n");
		print("<font color=\"#008000\"> \n");
		echo("You have logged in correctly. <br />");
		$errors = 0;
			// Start Session
			while($row = mysql_fetch_array($login))
			{
				$id = $row['login'];
			}
			$_SESSION['id'] = '$id';
			echo("Your session id is $id");
	}
}

// Finish Html Page
print("</font> \n");
print("			</td> \n");
print("		</tr> \n");
print("		<tr> \n");
print("			<td align=\"center\"> \n");
print("				<br /><a href=\"register.php\">Register</a> \n");
print("			</td> \n");
print("		</tr> \n");
print("</table> \n");
print("</center> \n");
print("</form> \n");
print("</body> \n");
print("</html> \n");

?>

Link to comment
https://forums.phpfreaks.com/topic/52227-solved-quick-question/#findComment-257633
Share on other sites

cheers thanks, what the problem was i was using login because that was the variable of the query instead of the column name. Sorry for that.

 

@chigley: It returned blank because it was meant to be $id instead of $login

 

Thanks for your help MadTechie + chigley  ;D

 

~ Chocopi

Link to comment
https://forums.phpfreaks.com/topic/52227-solved-quick-question/#findComment-257652
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.