Jump to content

Recommended Posts

this code was working and now its not, i dont think ive changed anything:

<?php

// Login.php

require_once('page_header.php');

// Declare Variables
// User Defined
	$username = $_POST['username'];
	$raw_password = $_POST['password'];
// Automatic
	$title = 'Chocopi :: Login';
	$password = md5($raw_password);
	$date = date('Ymd');
	$last_login = "UPDATE Mark SET last_login='$date' WHERE username='$username' && password='$password'";
	$login = mysql_query("SELECT id FROM Mark WHERE username='$username' && password='$password'");
	$login_check = mysql_num_rows($login);
	$get_date = "SELECT DATE_FORMAT(last_login, '%d %M %Y') as date FROM Mark";
	$reg_date = mysql_query($get_date) or die (mysql_error());
	$age = "SELECT DATEDIFF(last_login, reg_date) as daysreg";
	$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 align=\"center\">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");
		mysql_query($last_login) or die (mysql_error());
		echo("You have logged in correctly. <br />");
		$errors = 0;
			// Start Session
			session_start();
			$row = mysql_fetch_array($login, MYSQL_ASSOC);
			$id = $row['id'];
			$_SESSION['id'] = '$id';
// THIS IS THE LINE GIVING ME TROUBLE
// IT SHOULD PRODUCE THE ID BUT INSTEAD
// IT IS WRITING $ID
			echo("Welcome ".ucfirst($username)." (#".$id.")");
			print("<br />You last logged in on: \n");
			while ($row = mysql_fetch_assoc($reg_date))
			{
				echo $row['date'];
			}
			while ($row = mysql_fetch_assoc($age))
			{
				echo $row['daysreg'];
			}
	}
}

// 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");

?>

 

I cant for the life of me remember what i changed so i dont have a clue whats wrong

 

Thanks,

 

~ Chocopi

Link to comment
https://forums.phpfreaks.com/topic/52256-dont-know-whats-wrong/
Share on other sites

Nah i tried that but it still isnt responding

 

but the actual problem was with:

<?php
			$row = mysql_fetch_array($login, MYSQL_ASSOC);
			$id = $row['id'];
			$_SESSION['id'] = '$id';
			echo("Welcome ".ucfirst($username)." (#".$id.")");
?>

Link to comment
https://forums.phpfreaks.com/topic/52256-dont-know-whats-wrong/#findComment-257825
Share on other sites

no what i mean is, i didnt change any of the code , but its stopped working, which has confused the hell out of me.

 

<?php
echo("Welcome ".ucfirst($username)." (#".$id.")");
?>

 

This line produces (#$id) instead of (#1) or whatever the user id is

 

Thanks,

 

~ Chocopi

Link to comment
https://forums.phpfreaks.com/topic/52256-dont-know-whats-wrong/#findComment-258082
Share on other sites

There is some wrong code in there

 

eg

 

$_SESSION['id'] = '$id';

 

This will store the string '$id' into the session var and not the value in $id because you have it in single quotes.

 

<?php
$id = 123;

echo $id;          // 123
echo "$id";        // 123
echo '$id';        //  $id
?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/52256-dont-know-whats-wrong/#findComment-258088
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.