chocopi Posted May 20, 2007 Share Posted May 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/52256-dont-know-whats-wrong/ Share on other sites More sharing options...
chigley Posted May 20, 2007 Share Posted May 20, 2007 $age = "SELECT DATEDIFF(last_login, reg_date) as daysreg"; Shouldn't there be a FROM x somewhere in there? Quote Link to comment https://forums.phpfreaks.com/topic/52256-dont-know-whats-wrong/#findComment-257819 Share on other sites More sharing options...
chocopi Posted May 20, 2007 Author Share Posted May 20, 2007 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.")"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52256-dont-know-whats-wrong/#findComment-257825 Share on other sites More sharing options...
Barand Posted May 20, 2007 Share Posted May 20, 2007 Nah i tried that but it still isnt responding A classic example of how not to respond to help Quote Link to comment https://forums.phpfreaks.com/topic/52256-dont-know-whats-wrong/#findComment-257837 Share on other sites More sharing options...
AndyB Posted May 21, 2007 Share Posted May 21, 2007 ... i dont think ive changed anything ... I cant for the life of me remember what i changed That's a fairly unhelpful two-way shot. Quote Link to comment https://forums.phpfreaks.com/topic/52256-dont-know-whats-wrong/#findComment-257938 Share on other sites More sharing options...
chocopi Posted May 21, 2007 Author Share Posted May 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/52256-dont-know-whats-wrong/#findComment-258082 Share on other sites More sharing options...
chocopi Posted May 21, 2007 Author Share Posted May 21, 2007 now im even more confused. the code has fixed itself so now it is actually displaying the users id me = ??? oh well its all sorted ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/52256-dont-know-whats-wrong/#findComment-258083 Share on other sites More sharing options...
Barand Posted May 21, 2007 Share Posted May 21, 2007 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/52256-dont-know-whats-wrong/#findComment-258088 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.