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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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");} } } ?> Quote Link to comment 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']; } Quote Link to comment Share on other sites More sharing options...
Bravat Posted February 5, 2011 Author Share Posted February 5, 2011 This is the result: $row['ime'] = [ ] Quote Link to comment 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. Quote Link to comment 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 ] Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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.