Karlos2394 Posted March 8, 2009 Share Posted March 8, 2009 Well I've been coding PHP for about 6/7 months and i've never gotten to do sessions really but I have come across some problems and i think its the sessions. My errors are: Notice: Undefined index: user_name in C:\wamp\www\Blah\index.php on line 12 Notice: Undefined index: user_name in C:\wamp\www\Blah\index.php on line 12 <?php session_start(); require_once (DIRNAME(__FILE__) . '/db.php'); $Set = array(); $Get = db_query("SELECT `Set_Name`, `Set_Value` FROM `settings`"); while($r = mysql_fetch_array($Get)) { $Set[$r['Set_Name']] = $r['Set_Value']; } $Page = isset($_POST['Page']) ? $_POST['Page'] : ''; $Error = ''; if ($Page == 'Login') { $email = $_POST['email']; $password = $_POST['password']; if (trim($email) == '' || trim($password) == '') { $Error .= 'Please enter your email address and password.<br>'; } else { $result = db_query("SELECT id, name, password FROM users WHERE email='" . mysql_real_escape_string($email) . "'"); if (!($row = mysql_fetch_assoc($result))) { $Error .= 'The email address was not found.<br>'; } else if ($row['password'] != sha1($password)) { $Error .= 'The password did not match.<br>'; } else { $_SESSION['user_id'] = $row['id']; header('Location: index.php'); exit(); } } } echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head>'; echo sprintf("<title>%s Login</title>", stripslashes($Set['GameName'])); echo ' <style type="text/css"> div.ErrorText { color: #FF0000; width: 400px; text-align: center; } div.LBox { float: left; width: 150px; text-align: right; padding-right: 5px; } div.RBox { clear: right; } </style> </head> <body>'; echo sprintf("<div class='ErrorText'>%s</div>", $Error); echo ' <form action="login.php" method="post"> <div><input type="hidden" name="Page" value="Login"></div> <div class="LBox">Email address</div> <div class="RBox"><input type="text" name="email" size="30" maxlength="255"></div> <div class="LBox">Password</div> <div class="RBox"><input type="password" name="password" size="30"></div> <div class="LBox"> </div> <div class="RBox"><input type="submit" value="Log In" size="30"></div> </form> </body> </html> '; ?> <?php session_start(); error_reporting(E_ALL); $MemID = $_SESSION['user_id']; require_once 'db.php'; $ir = mysql_fetch_row(db_query(sprintf("SELECT * FROM users WHERE id=%u", $MemID))); ?> <?php include_once (DIRNAME(__FILE__) . '/core.php'); echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Index</title> </head> <body> Hello, '.$ir['user_name'].', what do you think you\'re doing? I\'m sorry, '.$ir['user_name'].', I can\'t let you do that.<br><br> <a href="logout.php">Log out</a> </body> </html>'; ?> Link to comment https://forums.phpfreaks.com/topic/148458-solved-sessions-arent-wroking-how-i-need-them-to/ Share on other sites More sharing options...
Karlos2394 Posted March 8, 2009 Author Share Posted March 8, 2009 A friend of mine fixed it for me, i simply turned mysql_fetch_row() into mysql_fetch_array() and it worked! Link to comment https://forums.phpfreaks.com/topic/148458-solved-sessions-arent-wroking-how-i-need-them-to/#findComment-779481 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.