chocopi Posted May 20, 2007 Share Posted May 20, 2007 For some reason, this does not work: <?php // Start Session while($row = mysql_fetch_array($login)) { $id = $row['login']; } $_SESSION['id'] = '$id'; echo("Your session id is $id"); ?> Any help would be appreciated. Thanks, ~ Chocopi Link to comment https://forums.phpfreaks.com/topic/52227-solved-quick-question/ Share on other sites More sharing options...
MadTechie Posted May 20, 2007 Share Posted May 20, 2007 check the SQL statment can you post all of that code as from what you have will never work.. Link to comment https://forums.phpfreaks.com/topic/52227-solved-quick-question/#findComment-257628 Share on other sites More sharing options...
chocopi Posted May 20, 2007 Author Share Posted May 20, 2007 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 More sharing options...
MadTechie Posted May 20, 2007 Share Posted May 20, 2007 try <?php // Start Session $row = mysql_fetch_array($login, MYSQL_ASSOC); $id = $row['login']; $_SESSION['id'] = '$id'; echo("Your session id is $id"); ?> Link to comment https://forums.phpfreaks.com/topic/52227-solved-quick-question/#findComment-257635 Share on other sites More sharing options...
chigley Posted May 20, 2007 Share Posted May 20, 2007 You need to use a session_start() somewhere! Link to comment https://forums.phpfreaks.com/topic/52227-solved-quick-question/#findComment-257638 Share on other sites More sharing options...
chocopi Posted May 20, 2007 Author Share Posted May 20, 2007 cheers, but it is still returning nothing even after doing both of the things you said ~ Chocopi Link to comment https://forums.phpfreaks.com/topic/52227-solved-quick-question/#findComment-257640 Share on other sites More sharing options...
chigley Posted May 20, 2007 Share Posted May 20, 2007 <?php // Start Session $row = mysql_fetch_assoc($login); echo "<pre>"; print_r($row); echo "</pre>"; ?> Run that and paste the output. Link to comment https://forums.phpfreaks.com/topic/52227-solved-quick-question/#findComment-257642 Share on other sites More sharing options...
MadTechie Posted May 20, 2007 Share Posted May 20, 2007 You missed the details from the SQL statement SELECT id FROM Mark WHERE username='$username' && password='$password' to SELECT id,login FROM Mark WHERE username='$username' && password='$password' EDIT: or $id = $row['id']; Link to comment https://forums.phpfreaks.com/topic/52227-solved-quick-question/#findComment-257646 Share on other sites More sharing options...
chocopi Posted May 20, 2007 Author Share Posted May 20, 2007 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 ~ Chocopi Link to comment https://forums.phpfreaks.com/topic/52227-solved-quick-question/#findComment-257652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.