Bravat Posted February 5, 2011 Share Posted February 5, 2011 I have this error, and I cann't find soluiton: Notice: Undefined index: ime in C:\wamp\www\web\login_public.php on line 26 Notice: Undefined index: ime in C:\wamp\www\web\login_public.php on line 27 This is the code: <?php require_once("public/includes/session.php"); ?> <?php require_once("public/includes/connection.php"); ?> <?php if(!$_POST['submit']){ header('refresh:0; url=index.php');} else { $korisnik = $_POST['korisnicko_ime']; $lozinka = $_POST['lozinka']; $lozinka_db = sha1($lozinka); if ($korisnik && $lozinka){ $query = mysql_query("SELECT * FROM korisnik WHERE korisnicko_ime = '$korisnik' "); $numrow = mysql_num_rows($query); if($numrow != 0){ while ($row = mysql_fetch_assoc($query)){ $korisnik_db = $row['korisnicko_ime']; $db_lozinka = $row['lozinka']; $ime = $row['ime']; } if ($korisnik == $korisnik_db && $lozinka_db == $db_lozinka){ echo "Uspesno ste ulogovani"; $_SESSION['ime'] == $ime; echo $_SESSION['ime']; } else { echo "Lozinka je netacna"; } } else {die("Korisnik ne postoji");} } } ?> What seems to be the problem Link to comment https://forums.phpfreaks.com/topic/226823-session-problem/ Share on other sites More sharing options...
BlueSkyIS Posted February 5, 2011 Share Posted February 5, 2011 the 'i' is a weird character in $_SESSION['ime'] == $ime; so $_SESSION['ime']; (without the wierd character) is undefined. Link to comment https://forums.phpfreaks.com/topic/226823-session-problem/#findComment-1170411 Share on other sites More sharing options...
Bravat Posted February 5, 2011 Author Share Posted February 5, 2011 Changed it to: $_SESSION['username'] == $ime; echo $_SESSION['username']; and it still does not work Link to comment https://forums.phpfreaks.com/topic/226823-session-problem/#findComment-1170416 Share on other sites More sharing options...
BlueSkyIS Posted February 5, 2011 Share Posted February 5, 2011 what "does not work"? do you still get the same notice? can you post the latest code? Link to comment https://forums.phpfreaks.com/topic/226823-session-problem/#findComment-1170417 Share on other sites More sharing options...
Bravat Posted February 5, 2011 Author Share Posted February 5, 2011 The same error is reported: Here is the code again ( basically changed first line and the $_SESSION lines): <?php session_start(); ?> <?php require_once("public/includes/connection.php"); ?> <?php if(!$_POST['submit']){ header('refresh:0; url=index.php');} else { $korisnik = $_POST['korisnicko_ime']; $lozinka = $_POST['lozinka']; $lozinka_db = sha1($lozinka); if ($korisnik && $lozinka){ $query = mysql_query("SELECT * FROM korisnik WHERE korisnicko_ime = '$korisnik' "); $numrow = mysql_num_rows($query); if($numrow != 0){ while ($row = mysql_fetch_assoc($query)){ $korisnik_db = $row['korisnicko_ime']; $db_lozinka = $row['lozinka']; $ime = $row['ime']; } if ($korisnik == $korisnik_db && $lozinka_db == $db_lozinka){ echo "Uspesno ste ulogovani"; $_SESSION['username'] == $ime; echo $_SESSION['username']; } else { echo "Lozinka je netacna"; } } else {die("Korisnik ne postoji");} } } ?> Link to comment https://forums.phpfreaks.com/topic/226823-session-problem/#findComment-1170419 Share on other sites More sharing options...
Pikachu2000 Posted February 5, 2011 Share Posted February 5, 2011 See if there's a values to assign. Temporarily add the line I've pointed out in the code, and see if $row['ime'] even has a value. if ($korisnik == $korisnik_db && $lozinka_db == $db_lozinka){ echo "Uspesno ste ulogovani"; echo '<br>$row[\'ime\'] = [ ' . $row['ime'] . ' ]<br>'; // <---- ADD THIS FOR DEBUGGING $_SESSION['ime'] == $ime; echo $_SESSION['ime']; } Link to comment https://forums.phpfreaks.com/topic/226823-session-problem/#findComment-1170421 Share on other sites More sharing options...
Bravat Posted February 5, 2011 Author Share Posted February 5, 2011 This is the result: $row['ime'] = [ ] Link to comment https://forums.phpfreaks.com/topic/226823-session-problem/#findComment-1170424 Share on other sites More sharing options...
Pikachu2000 Posted February 5, 2011 Share Posted February 5, 2011 Then there's your problem. The query isn't returning a value for that field, so you need to debug that and find out why. Link to comment https://forums.phpfreaks.com/topic/226823-session-problem/#findComment-1170426 Share on other sites More sharing options...
Bravat Posted February 5, 2011 Author Share Posted February 5, 2011 But when i use this line: echo '<br>$row[\'ime\'] = [ ' . $ime . ' ]<br>'; there is a positive result: $row['ime'] = [ Sasha ] Link to comment https://forums.phpfreaks.com/topic/226823-session-problem/#findComment-1170429 Share on other sites More sharing options...
Pikachu2000 Posted February 5, 2011 Share Posted February 5, 2011 Wait, I didn't see that you were already outside of the while() loop at that point. How many records is this query expected to return? Only one or more than one? Link to comment https://forums.phpfreaks.com/topic/226823-session-problem/#findComment-1170433 Share on other sites More sharing options...
Bravat Posted February 5, 2011 Author Share Posted February 5, 2011 Only one record. This is an attempt of login system. Link to comment https://forums.phpfreaks.com/topic/226823-session-problem/#findComment-1170435 Share on other sites More sharing options...
Bravat Posted February 5, 2011 Author Share Posted February 5, 2011 Well... human stupidity is so infinitive . Problem was in == (wonder why i put the). Just to say this is the best forum for helping novice PHP "programmers" . Thank you for help. Link to comment https://forums.phpfreaks.com/topic/226823-session-problem/#findComment-1170438 Share on other sites More sharing options...
Pikachu2000 Posted February 5, 2011 Share Posted February 5, 2011 Well, we all missed it too! Glad you noticed it. Link to comment https://forums.phpfreaks.com/topic/226823-session-problem/#findComment-1170440 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.